Basic Caching

Reduce cost and latency by caching Stagehand actions across runs

Demo preview
TypeScript
Source code
npx create-browser-app --template basic-caching
uvx create-browser-app --template basic-caching

Get started with Stagehand action caching

This template demonstrates Stagehand's caching feature by running the same Stripe Checkout workflow twice and comparing performance and cost. The first run executes actions normally (LLM calls), while the cached run reuses stored action results (cache hits) for near-instant execution and $0 additional LLM cost. It also shows how to configure a cache directory and inspect cache entries on disk.

Steps

  1. Run the workflow once without caching to establish a baseline
  2. Enable caching and set a cache directory to persist action results across runs
  3. Repeat the same workflow to populate the cache (first cached run)
  4. Run the script again to demonstrate cache hits (0 LLM calls, faster execution)
  5. Inspect the cache directory to see cached action entries