Cached Middleware Fetch Demo
View Code ↗
cachedFetch() Duration
1384.12ms
API Response Timestamp
2026-02-03T23:00:39.296Z
Random Value (to verify cache)
0.097854
Current Time
2026-02-03T23:00:39.330Z
How it works:
- The proxy fetches from an API endpoint that has a 1000ms delay
- Uses SWR (Stale-While-Revalidate) caching strategy with separate revalidate and expiry times
- Cache HIT: Fresh cached data served instantly (~0-5ms)
- Cache STALE: Cached data served instantly, background refresh triggered via waitUntil() (~0-5ms)
- Cache MISS: No cached data available, full API delay incurred (~1000ms)
- Data is fresh for 5 seconds (revalidate time)
- After 5 seconds, data becomes stale but is served instantly while refreshing in background
- After 30 seconds, cache expires completely and requires a fresh fetch
- The random value helps verify when the cache is actually being used
- Cache status provided via response headers: X-Cache-Status, X-Cache-Age, X-Cache-Expires-In