Agent skill

Caching

by zebbern in zebbern/claude-code-guide

Caching strategies — invalidation, TTL guidelines, cache keys, cache layers, and when not to cache.

MITAuto-check passedBackend & APIs

Install Caching

skills CLI
$ npx skills add zebbern/claude-code-guide --skill caching -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install zebbern/claude-code-guide caching --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/zebbern/claude-code-guide.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/caching .claude/skills/caching && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
caching
GitHub stars
4.6k
Token cost
~1.5k tokens
SKILL.md length
482 words
Files
1
Skills in repo
46
Repo updated
First seen
Licence
MIT

At a glance

Caching strategies — invalidation, TTL guidelines, cache keys, cache layers, and when not to cache.

  • Reviewing caching logic
  • SKILL.md covers WHEN_TO_USE, INVALIDATION, TTL_GUIDELINES and CACHE_KEYS, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Tasks that involve Caching

What it does

Caching is an agent skill from zebbern/claude-code-guide. Caching strategies — invalidation, TTL guidelines, cache keys, cache layers, and when not to cache. Use when implementing or reviewing caching logic.

Its SKILL.md is about 1.5k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Backend & APIs, covering Caching. It works with Redis. The repository describes itself as: Claude Code Guide - Setup, Commands, workflows, agents, skills & tips-n-tricks from beginner to power user! The licence is MIT.

When your agent uses it

  • Reviewing caching logic
  • Tasks that involve Caching

Example prompts

  • “/caching”

What it can do on your machine

Read from SKILL.md and the folder at commit 4698e3b. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Caching loads about 1.5k tokens when it runs. Until then it costs about 39 tokens; SKILL.md has 482 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~39
When it runs · the whole SKILL.md, loaded when a task matches
~1.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from zebbern/claude-code-guide at commit 4698e3b, republished under its MIT licence (© zebbern). 482 words, ~1,549 tokens.

Download SKILL.mdSave it as .claude/skills/caching/SKILL.md (or your agent's skills folder).
name
caching
description
Caching strategies — invalidation, TTL guidelines, cache keys, cache layers, and when not to cache. Use when implementing or reviewing caching logic.

WHEN_TO_USE

  • When implementing a cache layer (in-memory, Redis, CDN) for an API or service.
  • When choosing TTL values or invalidation strategies for cached data.
  • When designing cache key schemas to avoid collisions or stale-data bugs.
  • When reviewing code that reads from or writes to any cache.
  • When debugging stale data, cache stampedes, or inconsistent responses.
  • When configuring TanStack Query staleTime/gcTime for client-side caching.

INVALIDATION

  • [P0-MUST] Define an invalidation strategy for every cache. Stale data is worse than no cache.
  • [P0-MUST] Invalidate caches when the underlying data changes — do not rely solely on TTL expiry.
  • [P1-SHOULD] Prefer event-driven invalidation (on write/update/delete) over time-based expiry alone.
  • [P1-SHOULD] Use cache versioning (include a version key) when data schemas change.

TTL_GUIDELINES

  • [P1-SHOULD] Set TTLs based on data volatility: static config (hours/days), user profiles (minutes), real-time data (seconds or no cache).
  • [P1-SHOULD] Use stale-while-revalidate: serve stale data immediately while refreshing in the background.
  • [P2-MAY] Use shorter TTLs in development and longer TTLs in production.

CACHE_KEYS

  • [P0-MUST] Include all query parameters that affect the result in the cache key.
  • [P1-SHOULD] Use a consistent key format: <entity>:<id>:<variant> (e.g., user:123:profile, products:list:page=2).
  • [P1-SHOULD] Namespace keys by service or module to prevent collisions.
  • [P2-MAY] Hash long or complex keys to keep storage efficient.

CACHE_LAYERS

  • [P1-SHOULD] Use the appropriate cache layer for the use case:
LayerBest ForTTL Range
In-memory (Map, LRU)Hot data, single-instance appsSeconds to minutes
Redis / MemcachedShared cache across instances, sessionsMinutes to hours
CDN / EdgeStatic assets, public API responsesHours to days
HTTP cache headersBrowser caching, API responsesVaries by resource
  • [P1-SHOULD] Layer caches: check memory → Redis → origin. Write-through on miss.
Show full SKILL.md (213 more words)Show less

WHEN_NOT_TO_CACHE

  • [P0-MUST] Do not cache user-specific sensitive data (auth tokens, payment info) in shared caches.
  • [P1-SHOULD] Do not cache rapidly changing data where staleness causes incorrect behavior (inventory counts, real-time pricing).
  • [P1-SHOULD] Do not cache error responses — use short TTL or skip caching on failure.
  • [P2-MAY] Avoid caching when the computation is cheap and the data set is small.

CODE_EXAMPLES

In-memory LRU cache with TTL
ts
const cache = new Map<string, { value: unknown; expires: number }>();
const MAX_SIZE = 500;

export function getOrSet<T>(key: string, ttlMs: number, compute: () => T): T {
  const entry = cache.get(key);
  if (entry && entry.expires > Date.now()) return entry.value as T;

  const value = compute();
  if (cache.size >= MAX_SIZE) {
    // Evict oldest entry (first inserted)
    const oldest = cache.keys().next().value!;
    cache.delete(oldest);
  }
  cache.set(key, { value, expires: Date.now() + ttlMs });
  return value;
}
Redis stale-while-revalidate with ioredis
ts
import Redis from "ioredis";
const redis = new Redis(process.env.REDIS_URL);

export async function swr<T>(
  key: string,
  freshSec: number,
  staleSec: number,
  fetcher: () => Promise<T>,
): Promise<T> {
  const raw = await redis.get(key);
  if (raw) {
    const { value, createdAt } = JSON.parse(raw) as { value: T; createdAt: number };
    const ageMs = Date.now() - createdAt;
    if (ageMs < freshSec * 1000) return value; // Fresh — return immediately
    if (ageMs < staleSec * 1000) {
      // Stale — return cached, refresh in background
      fetcher().then((v) =>
        redis.set(key, JSON.stringify({ value: v, createdAt: Date.now() }), "EX", staleSec),
      );
      return value;
    }
  }
  const value = await fetcher();
  await redis.set(key, JSON.stringify({ value, createdAt: Date.now() }), "EX", staleSec);
  return value;
}
HTTP cache headers in Express/Hono
ts
// Immutable assets (hashed filenames)
app.use("/assets", (_, res, next) => {
  res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
  next();
});

// API responses — short cache with revalidation
app.get("/api/products", (_, res) => {
  res.setHeader("Cache-Control", "public, max-age=60, stale-while-revalidate=300");
  res.json(products);
});
TanStack Query cache configuration
tsx
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      staleTime: 5 * 60 * 1000, // Data fresh for 5 minutes
      gcTime: 30 * 60 * 1000,   // Garbage-collect after 30 minutes
      retry: 2,
      refetchOnWindowFocus: false,
    },
  },
});

// Usage in a component
const { data } = useQuery({
  queryKey: ["products", { page, category }], // Cache key includes params
  queryFn: () => fetchProducts({ page, category }),
});

ANTI_PATTERNS

  • Cache-and-forget — Caching data with no invalidation strategy. Data goes stale permanently.

    • Instead: define explicit invalidation (event-driven on write, or bounded TTL) for every cache key.
  • Uniform TTL — Using the same TTL (e.g., 1 hour) for all data regardless of volatility.

    • Instead: match TTL to data change frequency — seconds for prices, minutes for profiles, hours for configs.
  • Missing key parameters — Cache key omits user ID, locale, or query params, serving wrong data.

    • Instead: include every parameter that affects the result: products:list:page=2:locale=en.
  • Caching errors — Storing error responses (500s, timeouts) with long TTLs.

    • Instead: skip caching on failure, or use a very short TTL (5-10 seconds) to allow fast retry.
  • Cache stampede — All instances hit the origin simultaneously when a popular key expires.

    • Instead: use stale-while-revalidate, jittered TTLs, or a mutex lock to let one instance refresh.

© zebbern, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/caching of zebbern/claude-code-guide.

Open the folder on GitHubat commit 4698e3b

Compare with similar skills

Caching next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Caching compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Caching this skillzebbern/claude-code-guide4.6k—~1.5kAutomated safety check: PassMIT
Stripe Projectsfossasia/eventyay1.7k5 repos~2kAutomated safety check: NotesApache-2.0
FoundatioFoundatioFx/Foundatio2.1k—~3.9kAutomated safety check: PassApache-2.0
FastAPI-Redis SDK Developmentredis/fastapi-redis-sdk404—~2.5kAutomated safety check: NotesMIT
Caching Patternsdilolabs/nosia2131 repos~1.9kAutomated safety check: PassMIT
Cachingcodewithmukesh/dotnet-claude-kit7511 repos~1.4kAutomated safety check: PassMIT

Similar skills

  • Stripe Projects

    fossasia/eventyay

    A skill your agent uses when the user wants to provision infrastructure or third-party services using Stripe Projects.

    1.7k GitHub starsUsed in 5 repos~2k tokens
    Backend & APIsAuto-check: notes
  • Foundatio

    FoundatioFx/Foundatio

    A skill your agent uses when working with Foundatio infrastructure abstractions for .NET -- caching, queuing, messaging, file storage, distributed locking, or background jobs.

    2.1k GitHub stars~3.9k tokensUpdated today
    Backend & APIsAuto-check passed
  • FastAPI-Redis SDK Development

    redis/fastapi-redis-sdk

    Official

    Guides development on the fastapi-redis-sdk library itself - its connection lifecycle, dependency-injected caching, and async/sync bridging.

    404 GitHub stars~2.5k tokensUpdated 5 days ago
    Backend & APIsAuto-check: notes
  • Caching Patterns

    dilolabs/nosia

    Implements HTTP caching with ETags, fragment caching, Russian doll caching, and Solid Cache configuration.

    213 GitHub starsUsed in 1 repo~1.9k tokens
    Backend & APIsAuto-check passed
  • Caching

    codewithmukesh/dotnet-claude-kit

    Caching strategies for .NET 10 applications. An agent skill from codewithmukesh/dotnet-claude-kit.

    751 GitHub starsUsed in 1 repo~1.4k tokens
    Backend & APIsAuto-check passed
  • Caching Strategies

    ThibautBaissac/rails_ai_agents

    Implements Rails caching patterns for performance optimization.

    665 GitHub stars~1.4k tokensUpdated 4 mo ago
    Backend & APIsAuto-check passed

More from zebbern/claude-code-guide

All 46 skills in this repo
  • Localization Toolkit

    zebbern/claude-code-guide

    This skill should be used when setting up, auditing, or enforcing internationalization/localization in UI codebases (React/TS, i18next or similar, JSON locales), including installing/configuring the…

    4.6k GitHub starsUsed in 1 repo~1.3k tokens
    Auto-check passed
  • Audit Flow

    zebbern/claude-code-guide

    Interactive system flow tracing across CODE, API, AUTH, DATA, NETWORK layers with SQLite persistence and Mermaid export.

    4.6k GitHub stars~4.2k tokensUpdated today
    Auto-check passed
  • Chart Image

    zebbern/claude-code-guide

    Generate publication-quality PNG chart images from data, supporting line, bar, area, candlestick, pie, and heatmap charts.

    4.6k GitHub stars~2.7k tokensUpdated today
    Auto-check passed
  • Code To Diagram

    zebbern/claude-code-guide

    Analyze codebases and automatically generate architecture diagrams, flowcharts, and org charts.

    4.6k GitHub stars~972 tokensUpdated today
    Auto-check passed
  • Code Vuln Audit

    zebbern/claude-code-guide

    Scan code for security issues: dependency vulnerabilities (npm/pip audit), secret leaks (regex and entropy analysis), and OWASP anti-patterns like SQL injection, XSS, or command injection.

    4.6k GitHub stars~1.3k tokensUpdated today
    Auto-check passed
  • Data Viz Renderer

    zebbern/claude-code-guide

    Generate self-contained HTML/SVG infographics from JSON data, including stat cards, bar charts, flow diagrams, and mixed dashboards.

    4.6k GitHub stars~1.3k tokensUpdated today
    Auto-check passed

Works with

Categories

Questions about Caching

What does Caching do?

Caching strategies — invalidation, TTL guidelines, cache keys, cache layers, and when not to cache. Caching is an agent skill from zebbern/claude-code-guide. Caching strategies — invalidation, TTL guidelines, cache keys, cache layers, and when not to cache.

When should I use Caching?

Caching fits situations like: reviewing caching logic; tasks that involve Caching.

How do I install Caching in Claude Code?

Run `npx skills add zebbern/claude-code-guide --skill caching -a claude-code`. Or copy the skill folder (skills/caching in zebbern/claude-code-guide) into .claude/skills/caching in your project. Claude Code loads it when a task matches its description.

How do I install Caching in Codex?

Run `npx skills add zebbern/claude-code-guide --skill caching -a codex`. Or copy the skill folder (skills/caching in zebbern/claude-code-guide) into .agents/skills/caching in your project. Codex loads it when a task matches its description.

Can I use Caching in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add zebbern/claude-code-guide --skill caching -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/caching, .gemini/skills/caching, .github/skills/caching and .opencode/skills/caching in your project.

What does Caching need to run?

SKILL.md names no scripts, command-line tools or credentials: Caching is instructions for the agent only.

Does Caching access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Caching safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Caching use?

Caching is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Caching use?

About 1.5k tokens (SKILL.md is roughly 6.2k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Caching?

Skills that share tags, products or a category with Caching: Stripe Projects (fossasia/eventyay, 1.7k stars), Foundatio (FoundatioFx/Foundatio, 2.1k stars), FastAPI-Redis SDK Development (redis/fastapi-redis-sdk, 404 stars) and Caching Patterns (dilolabs/nosia, 213 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Caching?

zebbern (a GitHub user) maintains it in zebbern/claude-code-guide, which has 4,648 GitHub stars. The repository holds 46 skills in this directory. The repository was last updated on October 7, 2026.

Source: zebbern/claude-code-guide on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.