cache-guide

Guides selection between cache() DSL and "use cache" directive for Rango route and function caching.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Rango offers two caching mechanisms — the route-level cache() DSL and the function-level "use cache" directive — and choosing the wrong one leads to stale data, lost side effects, or cache-poisoning bugs. This Skill provides a decision guide that maps your caching problem to the correct mechanism. ## Core Features & Use Cases - Decision framework: A fast-choice flowchart covering route/segment caching, function-level caching, runtime conditions, and argument-keyed entries. - Correctness guarantees: Explains boundary guards, tainted context variables, version-segmented store keys, and stale-while-revalidate behavior so you avoid serving wrong or cross-deploy data. - Composition patterns: Shows how cache() and "use cache" nest, why loaders always stay fresh, and how TTL windows interact. - Use Case: You are caching a product page and need the rendered segment cached for 5 minutes but the price query refreshed per argument — this guide tells you to wrap the route in cache({ ttl: 300 }) and mark the query function with "use cache". ## Quick Start Ask the AI which caching mechanism to use for caching an expensive database query shared across multiple Rango routes.

Frequently Asked Questions about cache-guide

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

FAQPage Schema
How do I choose between cache() and "use cache" in Rango?

Use cache() to cache entire routes or segment trees with runtime conditions and custom keys, and use "use cache" to cache individual function results keyed by arguments. cache() skips the whole handler on hit; "use cache" skips only the wrapped function body.

How do I cache a database query shared across multiple routes?

Add the "use cache" directive inside the query function, optionally with a profile like "use cache: short". The cache key includes the function identity and serialized non-tainted arguments, so different arguments produce separate entries.

Does Rango cache() cache loader data?

No, loaders are always excluded from route-level cache() and resolve fresh on every request, even on a full segment cache hit. To cache a loader's data, opt in explicitly with loader(Fn, () => [cache({ ttl: ... })]).

Why do cookies() and headers() throw inside a cached function?

They throw because per-request data is not part of the cache key, so reading them inside a cached scope would bake one request's data into a shared entry. Response side effects like ctx.header() are also blocked since they would be lost on a cache hit.

What happens to cached entries after a new deployment?

CFCacheStore prefixes every store key with the build version, so a new deploy never reads a previous build's entries. This prevents cross-deploy shape drift but means every deploy starts with a cold data cache.

Does an inner "use cache" with a shorter TTL refresh faster than its outer cache()?

No, the outer cache window bounds everything inside it. On an outer cache hit no inner code runs, so an inner shorter TTL only takes effect when the enclosing cache recomputes; use a loader for data that must stay fresher.