document-cache

Cache complete HTTP responses in Rango's app store using Cache-Control s-maxage policy.

Updated Nov 7, 2025
One-click install
npx skills add https://github.com/rangojs/rango --skill document-cache-rangojs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: document-cache
Source: https://github.com/rangojs/rango/tree/main/packages/rangojs-router/skills/document-cache
Command: npx skills add https://github.com/rangojs/rango --skill document-cache-rangojs

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Full-page responses in a Rango application are regenerated on every request even when the content is identical for all visitors. This Skill explains how to cache complete HTML and RSC responses in the app-level cache store so repeat requests are served from the store instead of re-running handlers and loaders. ## Core Features & Use Cases - Store-backed response caching: Add createDocumentCacheMiddleware() to the router so responses with a Cache-Control: s-maxage header are stored and replayed, with stale-while-revalidate enabling background revalidation. - Route opt-in via headers: Handlers opt into caching by setting s-maxage, while routes without the header are never cached, keeping dynamic pages like dashboards live. - Cache observability and control: Options like skipPaths, keyGenerator, isEnabled, and debug control what is cached, and the x-document-cache-status header reports HIT, STALE, or MISS. - Use Case: A blog index and post pages set s-maxage=300, stale-while-revalidate=3600 so anonymous traffic is served from a Cloudflare-backed store while the dashboard remains uncached. ## Quick Start Add createDocumentCacheMiddleware to my Rango router with a CFCacheStore and show me how to opt my blog routes into caching with Cache-Control headers.

Frequently Asked Questions about document-cache

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I cache full page responses in a Rango router app?

Add createDocumentCacheMiddleware() to the router with .use() and configure an app-level cache store on createRouter({ cache }). Routes opt in by setting a Cache-Control header containing s-maxage in their handlers.

What is the difference between document cache and segment cache in Rango?

Document cache stores the entire response and is opted into with Cache-Control s-maxage, suiting static pages. Segment cache uses cache({ ttl, swr }) per segment, suiting pages where different parts have different freshness requirements.

Does the document cache middleware work with Cloudflare and Vercel?

Yes. With CFCacheStore the response family can use Cloudflare's edge/KV tiers, and with VercelCacheStore it uses Vercel Runtime Cache. The middleware still runs inside the function, unlike a platform CDN cache.

Which responses are not cached by the document cache middleware?

Server actions, loader requests, non-GET requests, non-200 responses, and responses without an s-maxage Cache-Control directive are never cached. Only 200 OK responses with s-maxage qualify.

Why is my cached page served to the wrong users?

Document caching freezes the whole response, so it is only safe when the complete response is public and identical for every request sharing the cache key. Use skipPaths, isEnabled, or a custom keyGenerator to exclude personalized responses.