cache-strategy

cache-strategy is a skill for Claude Code, Codex from TerminalSkills/skills. It costs 88 tokens per session (1,563 once invoked), scanned A, original, Apache-2.0.

A guide to adding caches to APIs and web applications using Redis or Memcached, which store frequently used data for quick access. It covers several ways to read, update, expire, and invalidate cached data.

In plain words
What is it for?
Use it to choose and implement cache-aside, write-through, or write-behind designs, set expiration times, invalidate entries, and prevent cache stampedes.
Why use it?
Repeated database queries can slow an application and increase database load. A suitable caching design can reduce repeated work while handling stale data and simultaneous requests safely.

Skill for Claude CodeCodex

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

Good fit Use it to choose and implement cache-aside, write-through, or write-behind designs, set expiration times, invalidate entries, and prevent cache stampedes.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/terminalskills/skills/cache-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 TerminalSkills/skills --skill cache-strategy
Clone the repo
git clone --depth 1 https://github.com/TerminalSkills/skills

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 cache-strategy

README.md
[![agentmods](https://agentmods.dev/badge/skills/terminalskills/skills/cache-strategy/github.svg)](https://agentmods.dev/skills/terminalskills/skills/cache-strategy)
Your own site
<a href="https://agentmods.dev/skills/terminalskills/skills/cache-strategy"><img src="https://agentmods.dev/badge/skills/terminalskills/skills/cache-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 cache-strategy

Your own site · 80×15
<a href="https://agentmods.dev/skills/terminalskills/skills/cache-strategy"><img src="https://agentmods.dev/badge/skills/terminalskills/skills/cache-strategy.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 88 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,563 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. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
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.00088 $0.01563
Opus 5.5 $0.00035 $0.00625
Sonnet 5.5 $0.00018 $0.00313
Haiku 4.5 $0.00009 $0.00156

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

Security

Grade A, and why

cache-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 9d 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.

skills/cache-strategy/SKILL.md · 160 lines

How it starts

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

Cache Strategy

Overview

This skill helps you design and implement multi-layer caching strategies for high-traffic APIs. It covers choosing the right caching pattern for your data access profile, configuring TTLs, preventing cache stampedes, and setting up cache invalidation that actually works in production.

Instructions

1. Analyze the caching opportunity

Before adding caching, identify what to cache by examining query patterns:

// Instrument your API routes to log response times and call frequency
// Look for: high frequency + low change rate = best cache candidates
// Example analysis output:
// GET /api/products      → 12,000 req/min, changes every 30min → CACHE (TTL: 5min)
// GET /api/products/:id  → 8,000 req/min, changes on update   → CACHE (invalidate on write)
// POST /api/orders       → 200 req/min, always unique          → DO NOT CACHE
// GET /api/user/profile  → 3,000 req/min, changes rarely       → CACHE (TTL: 15min)

2. Implement cache-aside pattern (most common)

The application checks cache first, falls back to database, then populates cache:

import { Redis } from "ioredis"; // ioredis 6: named import is the documented TypeScript form

// ioredis queues commands while disconnected; maxRetriesPerRequest makes them fail
// fast so a Redis outage falls through to the database instead of hanging requests.
const redis = new Redis({ host: "localhost", port: 6379, maxRetriesPerRequest: 3 });

async function getCached<T>(
  key: string,
  fetcher: () => Promise<T>,
  ttlSeconds: number = 300
): Promise<T> {
  try {
    const cached = await redis.get(key);
    if (cached) return JSON.parse(cached);
  } catch (err) {
    console.warn(`cache read failed for ${key}, going to the database`, err);
    return fetcher();
  }

  const data = await fetcher();
  // A failed write must not fail the request; the next read simply misses again.
  await redis.set(key, JSON.stringify(data), "EX", ttlSeconds).catch(() => undefined);
  return data;
}

// Usage in route handler
app.get("/api/products/:id", async (req, res) => {
  const product = await getCached(
    `product:${req.params.id}`,
    () => db.products.findById(req.params.id),
    600 // 10 minutes
  );
  res.json(product);
});

Read the full file on GitHub · 160 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 9d ago Changed · +8 lines 1f4e1c5f79c1
  2. 1mo ago First seen · 152 lines · 88 tokens per session scan A 0995d4259aca

Subscribe to this mod's changes

cache-strategy is a skill published in the GitHub repository TerminalSkills/skills (177 stars, last pushed today), licensed Apache-2.0. It adds 88 tokens to every session and 1,563 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-05.

Related

Other skills, from other repositories

spring-data-redis

Use when implementing caching, session storage, rate limiting, or any Redis integration. Covers cache-aside pattern, key naming, TTL strategy, and serialization config.

rrezartprebreza/spring-boot-skills · 37 tokens

python-redis-module-skill

A Python integration guide for adding Redis to an existing FastAPI project. Redis is a fast shared data store commonly used for temporary data, sessions, locks, counters, and messages.

jiushiwon/wg-skills · 109 tokens

springboot-redis-module-skill

A Spring Boot integration module for Redis, a fast data store often used for temporary data, shared login sessions, coordination between servers, request limits, and message streams. It is intended for an existing Spring Boot project.

jiushiwon/wg-skills · 110 tokens

spring-boot-cache

Provides patterns for implementing Spring Boot caching: configures Redis/Caffeine/EhCache providers with TTL and eviction policies, applies @Cacheable/@CacheEvict/@CachePut annotations, validates cache hit/miss behavior, and exposes metrics via Actuator. Use when adding caching to Spring Boot services, configuring…

giuseppe-trisciuoglio/developer-kit · 79 tokens

nw-sd-patterns

Core distributed systems patterns - load balancing, caching, sharding, consistent hashing, message queues, rate limiting, CDN, Bloom filters, ID generation, replication, conflict resolution, CAP theorem.

nWave-ai/nWave · 43 tokens

background-job-orchestrator

Expert in background job processing with Bull/BullMQ (Redis), Celery, and cloud queues. Implements retries, scheduling, priority queues, and worker management. Use for async task processing, email campaigns, report generation, batch operations. Activate on "background job", "async task", "queue", "worker", "BullMQ"…

curiositech/some_claude_skills · 95 tokens