Index of every page on this site: llms.txt
All skills
Run it yourself

Designs, audits and implements caching for a specific website or app across every layer, including HTTP/browser headers (Cache-Control, ETag, Vary), service workers, CDNs and edge (Cloudflare, Vercel, Netlify, Fastly, CloudFront, Akamai), nginx/Varnish, in-process and Redis/Valkey/Memcached caches, database and ORM caches, framework caching (Next.js use cache/ISR, Nuxt, SvelteKit, Astro, Rails, Django, Laravel, Spring, ASP.NET), CMS, REST/GraphQL APIs, mobile clients, LLM prompt and semantic caching, and CI build caches. Detects the stack, classifies every route, and writes a validated caching plan covering invalidation, stampede protection, cache security and verification. Use when the user mentions caching, stale content, purging, CDN or Redis setup, or when pages are slow, TTFB is high, or origin, database or hosting costs are too high, even if they never say "cache". Not for clearing local package-manager caches or explaining CPU caches.

  • 81 files
  • 630.9 KB
  • MIT
  • Updated 4 weeks ago
  • GitHub
Use this Skill: https://skilld.dev/gh/onlymoein/master-cache-skill/caching-strategy

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesframeworksnuxt-nitro.md

≈1.6k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Nuxt and Nitro

Last reviewed: 2026-10-27 · Applies to: Nuxt 4.6.x (and 3.21.x) on nitropack 2.13; Nitro 3 / Nuxt 5 are pre-release

Contents

  • When to read this
  • How to detect
  • Default recipe
  • Rules and gotchas
  • Cached handlers and functions
  • Client data: useFetch and useAsyncData
  • Hosting
  • Version notes
  • Verify
  • Sources

When to read this

When nuxt, nitropack or nitro is a dependency. Stable Nuxt 4.6 runs on nitropack 2.13, so Nitro v2 caching docs apply.

How to detect

nuxt in package.json; nuxt.config.ts (routeRules, nitro.storage, nitro.preset); standalone Nitro: nitro.config.ts (defineNitroConfig). nitro 3.x beta or Nuxt 5.0.0-x means pre-release APIs.

Default recipe

// nuxt.config.ts
export default defineNuxtConfig({
  routeRules: {
    '/':            { prerender: true },
    '/products/**': { swr: 3600 },                 // shared, server/proxy cached, SWR
    '/blog/**':     { isr: 600 },                  // CDN-cached on Vercel/Netlify
    '/account/**':  { headers: { 'cache-control': 'private, no-cache' } },
    '/_nuxt/**':    { headers: { 'cache-control': 'public, max-age=31536000, immutable' } },
  },
  nitro: {
    storage: { cache: { driver: 'redis', url: process.env.REDIS_URL } },   // shared across instances
  },
})
// server/api/stars/[repo].get.ts
export default defineCachedEventHandler(async (event) => {
  const repo = getRouterParam(event, 'repo')
  return (await $fetch(`https://api.github.com/repos/${repo}`)).stargazers_count
}, { maxAge: 3600, staleMaxAge: 86400, name: 'ghStars', getKey: (event) => getRouterParam(event, 'repo')! })

Rules and gotchas

  1. defineCachedEventHandler/defineCachedFunction default maxAge is 1 second. Always set maxAge (and staleMaxAge for bounded staleness; -1 = always serve stale).
  2. Cached handlers drop all incoming request headers unless listed in varies. Anything depending on auth, cookies or locale must use varies/getKey, or must not be cached. For multi-tenant hosts use varies: ['host', 'x-forwarded-host'].
  3. The cache: storage mount is in-memory per instance in production (fs in dev). Multi-instance or serverless deployments need a shared driver (Redis, Cloudflare KV, Upstash) or invalidation will be inconsistent.
  4. Treat swr/isr routes as shared: never use them for per-user pages.
  5. isr gets CDN behavior only on the Vercel and Netlify presets; elsewhere it degrades to swr-style server caching.
  6. Routes with isr/swr also generate _payload.json. Nuxt CVE-2025-27415 let a CDN that ignores the query string cache /?/_payload.json JSON as the page (fixed in 3.16.0); keep Nuxt patched and keep query strings in the CDN key for payload URLs.
  7. Cache keys are normalized (non-word chars stripped: /api/products/sale-items → api/productssaleitems.json). Use escapeKey() when building keys to invalidate.
  8. defineCachedFunction results are JSON-serialized (no Map/Set/Symbol). On edge workers pass event first so Nitro can waitUntil the background refresh.
  9. Hybrid rendering (routeRules) doesn't work with nuxt generate.

Cached handlers and functions

Options: base (storage mount, default cache), name, group (nitro/handlers | nitro/functions), getKey, integrity, maxAge (default 1), staleMaxAge (default 0), swr (default true), shouldInvalidateCache, shouldBypassCache, varies.

Invalidate by removing the storage key:

// key = `${group}:${name}:${getKey(...)}.json`; handlers use group nitro/handlers, functions nitro/functions
await useStorage('cache').removeItem('nitro:handlers:ghStars:nuxt.json')

Route rules can select a custom mount: { cache: { maxAge: 60, base: 'redis' } }.

Client data: useFetch and useAsyncData

  • Calls with the same key share data, error, status; handler, transform, pick, getCachedData and default must match across them. Without a key, Nuxt generates one from file and line.
  • Server data travels in the payload (devalue), so hydration doesn't refetch. Shrink it with pick/transform. serialize: false (4.6) keeps data out of the payload (client refetches).
  • Default getCachedData returns payload/static data only during hydration (and only caches across navigations with experimental.payloadExtraction). Write a custom getCachedData(key, nuxtApp, ctx) with a timestamp check for client-side SWR across navigations.
  • Invalidate with refresh()/clear() per call, or refreshNuxtData(keys)/clearNuxtData(keys) globally. Clear on logout.
  • dedupe defaults to 'cancel'; enabled (4.5) and middleware (4.6) options exist.

Hosting

Target Behavior
Vercel / Netlify presets isr/swr map to the platform CDN; see platform references
Node server preset swr caches full responses in Nitro storage; put a CDN in front with explicit headers
Cloudflare Use nitro.storage.cache on KV (eventual, up to 60 s)
Docker/Kubernetes Redis storage driver; CDN purge hook on content change

Version notes

  • Nuxt 4.5: useAsyncData enabled. Nuxt 4.6: serialize, middleware options.
  • Nitro 3 (beta) and Nuxt 5 (pre-release) move to h3 v2; cached-handler names may change (unverified). Don't recommend Nitro 3 APIs for stable apps.
  • defineRouteRules() in pages is experimental (experimental.inlineRouteRules).
<details><summary>Old patterns</summary>
  • Nuxt 2 serverMiddleware + nuxt-ssr-cache.
  • Relying on the default memory cache driver in multi-instance production.
</details>

Verify

curl -s -o /dev/null -D - https://example.com/products/1 | grep -iE 'cache-control|age|x-nitro|cache-status'
curl -s -o /dev/null -D - 'https://example.com/?/_payload.json' | grep -iE 'content-type|cache-control'   # must not be cached as the page

Check that two instances return the same cached value after an invalidation (shared storage working).

Sources

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at 46a6ee6. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 weeks ago.

Activeupdated 4 weeks ago
metadata
{
  "version": "1.1.1",
  "last-reviewed": "2026-10-28"
}
Other metadata
compatibility
Live header probes need network access and user-supplied URLs; every other step runs offline with the Python 3 standard library.

README badge

README badge for onlymoein/master-cache-skill