caching-strategy

caching-strategy is a skill for Claude Code, Codex from tmj-90/gaffer. It costs 95 tokens per session (1,431 once invoked), scanned A, original, Apache-2.0.

A guide for adding or fixing a cache, which stores a previous result so the application can reuse it instead of doing the same work again. It addresses what is stored, how long it stays valid, and what happens when it becomes outdated.

In plain words
What is it for?
Use it for in-memory or request caches, HTTP cache headers, CDN rules, Redis caches, and cached database or query results.
Why use it?
It prevents stale or incorrect results caused by unclear cache rules, and helps ensure caching is used only where repeated work is actually a problem.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it for in-memory or request caches, HTTP cache headers, CDN rules, Redis caches, and cached database or query results.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/tmj-90/gaffer/caching-strategy
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add tmj-90/gaffer --skill caching-strategy
Clone the repo
git clone --depth 1 https://github.com/tmj-90/gaffer

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for caching-strategy

README.md
[![agentmods](https://agentmods.dev/badge/skills/tmj-90/gaffer/caching-strategy/github.svg)](https://agentmods.dev/skills/tmj-90/gaffer/caching-strategy)
Your own site
<a href="https://agentmods.dev/skills/tmj-90/gaffer/caching-strategy"><img src="https://agentmods.dev/badge/skills/tmj-90/gaffer/caching-strategy/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for caching-strategy

Your own site · 80×15
<a href="https://agentmods.dev/skills/tmj-90/gaffer/caching-strategy"><img src="https://agentmods.dev/badge/skills/tmj-90/gaffer/caching-strategy.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 95 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,431 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00095 $0.01431
Opus 5.5 $0.00038 $0.00572
Sonnet 5.5 $0.00019 $0.00286
Haiku 4.5 $0.00010 $0.00143

Measured 16d ago against content hash 7d2da798b7c3, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

caching-strategy scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 16d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

runner/skills/caching-strategy/SKILL.md · 88 lines

How it starts

The opening of the file, as written. The whole thing — 88 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Add or fix a cache

A cache trades freshness for speed, and every cache goes stale in a specific way. Write the story before the code: key, scope, lifetime, invalidation, the race that can leave a stale value behind, and what happens when the cache is down. A cache without an invalidation plan is a bug on a delay.

Steps

  1. Prove the need. A measurement showing the same expensive read repeated (the performance-profiling skill). If the fix is "stop calling it twice", batch the query, or add an index (the sql-query-performance skill), do that instead.
  2. Choose the innermost layer that solves it. Request-scoped memo (no invalidation problem); process memory (fast, per instance, diverges across instances); a shared store such as Redis (consistent across instances, one more dependency); HTTP caching (RFC 9111: Cache-Control, ETag/If-None-Match → 304, CDN). Call search_lore for the repo's cache helper, key prefixing and serializer; use it.
  3. Design the key. Every input that changes the output is in the key: identifiers, tenant, the caller's permission scope, locale, query parameters, and a schema or code version. Missing tenant = data leak; missing version = old shapes after a deploy. HTTP: Vary on every request header the response depends on.
  4. Set the TTL from the data. Ask how stale this can be before someone is harmed; that is the TTL. Add ±10–20 % jitter so keys written together do not expire together. TTL is the safety net, not the invalidation plan.
  5. Invalidate on every write path, after commit. List each code path that changes the source data in a comment beside the cache, and delete (not update) the key after the transaction commits. Deleting before commit lets a reader repopulate the old value. Also close the stale-set race: reader A misses and reads the old row, writer B commits and deletes the key, A then sets the old value, which stays until TTL. Guard with one of: versioned keys (bump a version on write; readers use the current version), a compare-on-set against a version tombstone (the write path replaces the entry with a tombstone carrying the new row version instead of deleting it, and a set succeeds only if its version is ≥ the stored one — a plain delete leaves nothing to compare), lease tokens that a delete invalidates (as in Facebook's memcache), or a short TTL when brief staleness is acceptable and stated.
  6. Guard against stampedes on expensive keys. On a miss, let one caller recompute and the rest wait or serve stale: request coalescing / single-flight per key in process, a short lock key (SET key NX PX) across processes, probabilistic early refresh (XFetch), or stale-while-revalidate / stale-if-error (RFC 5861) for HTTP. The lock needs a timeout and a fallback so a crashed recomputer does not block reads; an expiring lock is acceptable here only because it guards work, not correctness (a lock that protects a write needs fencing: the concurrency-and-async skill, step 5).
  7. Fail open. A cache timeout or outage falls back to the source with a short client timeout; it is never a user-facing error. Do not cache errors; cache "not found" only deliberately and briefly. Emit hit, miss and eviction counters so the cache's value and a cold or failing store are visible.
  8. Never share what must not be shared. Authorization decisions, secrets and per-user data are per-user keys or not cached. Responses that vary by session are Cache-Control: private or no-store; a CDN never caches a response carrying Set-Cookie or user data.
  9. Test each behaviour, one test per AC exercising the AC's own behaviour, plus: hit, miss, invalidation after each listed write path, TTL expiry with a fake clock (no sleeps), cache-down fallback, two tenants never sharing a value, and for expensive keys N concurrent misses causing one recomputation (parallel, per the concurrency-and-async skill's step 9). For HTTP, assert the exact Cache-Control, ETag and Vary headers and the 304 path.
  10. Evidence with the record-evidence skill: before/after numbers and test output.

Read the full file on GitHub · 88 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 16d ago Changed · +24 lines 7d2da798b7c3
  2. 19d ago First seen · 64 lines · 95 tokens per session scan A 425fbeea16df

Subscribe to this mod's changes

caching-strategy is a skill published in the GitHub repository tmj-90/gaffer (2 stars, last pushed 17d ago), licensed Apache-2.0. It adds 95 tokens to every session and 1,431 once invoked, about $0.0004 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-28.