netlify-caching

Configure CDN caching, cache keys, tags, and purging for Netlify Functions and Edge Functions.

Updated May 19, 2026
One-click install
npx skills add https://github.com/costrict-plugins-repo/anthropic-netlify-skills --skill netlify-caching-costrict-plugins-repo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: netlify-caching
Source: https://github.com/costrict-plugins-repo/anthropic-netlify-skills/tree/main/codex/skills/netlify-caching
Command: npx skills add https://github.com/costrict-plugins-repo/anthropic-netlify-skills --skill netlify-caching-costrict-plugins-repo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @netlify/functions, @netlify/cache.

What problem does it solve? Dynamic responses from Netlify Functions and Edge Functions are not cached by default, so every request re-invokes your function. This Skill shows how to opt into Netlify's CDN cache with the right headers, vary cache keys correctly, tag and purge content, and debug cache behavior. ## Core Features & Use Cases - Header-based caching: Set Netlify-CDN-Cache-Control with max-age, s-maxage, stale-while-revalidate, and durable directives to cache dynamic responses on Netlify's CDN. - Cache key variation and tags: Use Netlify-Vary to vary by query, header, cookie, country, or language, and Netlify-Cache-Tag to tag responses for targeted purging via purgeCache or the purge API. - Programmatic Cache API: Use the caches global or the @netlify/cache helpers (fetchWithCache, cacheHeaders, getCacheStatus) to cache arbitrary fetches and components inside functions. - Use Case: You have an expensive third-party API call in a serverless function. Add Netlify-CDN-Cache-Control: public, durable, max-age=60, stale-while-revalidate=120, tag it, and purge by tag whenever the underlying data changes. ## Quick Start Ask the agent to add CDN caching with a 60-second TTL and stale-while-revalidate to my Netlify Function response and show me how to verify it with the Cache-Status header.

Frequently Asked Questions about netlify-caching

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

FAQPage Schema
How do I cache a Netlify Function response on the CDN?

Set the Netlify-CDN-Cache-Control header on the function response, for example 'public, durable, max-age=60, stale-while-revalidate=120'. Dynamic responses are not cached by default, so you must opt in with this header on a GET route.

How do I purge the Netlify cache by tag?

Call purgeCache from @netlify/functions inside a deployed function, passing tags, and optionally deployAlias or domain. From CI or local scripts, pass a personal access token and siteID, or POST to the api.netlify.com/api/v1/purge endpoint.

Why is my Netlify Function response not being cached?

Only GET requests are cached, and netlify dev does not emulate the CDN cache, so local misses are expected. Verify on a deployed URL by inspecting the Cache-Status header for 'Netlify Edge'; hit or miss values.

Does Netlify-Vary work with query strings and cookies?

Yes, Netlify-Vary supports query, header, cookie, country, and language variation with pipe-delimited value lists. Without it, the full query string is the cache key, so enumerate only the parameters that change the response.

What is the difference between the durable cache and edge cache on Netlify?

The edge cache is per-node, while the durable cache is a shared store co-located with your functions region that edge nodes check before invoking the function. The durable directive works only for serverless functions, not Edge Functions.

Can I use the Cache API in local development with my own dev server?

The caches global is provided by Netlify's runtimes and netlify dev, but not by framework dev servers. Import caches from the @netlify/cache module instead; locally nothing persists, so lookups return nothing and writes no-op.