Skip to main content

Recipe

This recipe shows how to use persistentStore (TypeScript) or persistent_store (Python) to cache scraped data across executions of the same project.
TypeScript
import { BrowserContext, Page } from "playwright";
import { persistentStore } from "@intuned/runtime";

interface Params {}

export default async function handler(
  params: Params,
  page: Page,
  context: BrowserContext
) {
  const CACHE_KEY = "consultations";

  // 1. Check cache first
  const cached = await persistentStore.get(CACHE_KEY);
  if (cached) {
    return cached;
  }

  // 2. Cache miss — navigate and scrape the page
  await page.goto("https://sandbox.intuned.dev/consultations/list");
  await page.waitForSelector(".consultation-item");

  const consultations = await page.locator(".consultation-item").evaluateAll(
    (items) =>
      items.map((item) => ({
        id: item.getAttribute("data-consultation-id"),
        status: item.querySelector(".consultation-status")?.textContent?.trim(),
        name: item.querySelector(".client-name .data-value")?.textContent?.trim(),
        date: item.querySelector(".consultation-date .data-value")?.textContent?.trim(),
        topic: item.querySelector(".consultation-topic .data-value")?.textContent?.trim(),
      }))
  );

  // 3. Store for future runs
  await persistentStore.set(CACHE_KEY, consultations);

  return consultations;
}

How it works

  1. Check the cache — Use persistentStore.get() / persistent_store.get() to look for existing data.
  2. Return cached data — If found, return immediately without re-scraping.
  3. Scrape and store — On cache miss, navigate to the page, extract data, and store it with persistentStore.set() / persistent_store.set() for future runs.
Data persists across all executions within the same project, making it ideal for data that doesn’t change frequently.

persistentStore (TypeScript)

TypeScript SDK helper for persistent key-value storage

persistent_store (Python)

Python SDK helper for persistent key-value storage