Skip to main content
skill CX Codex

caching-strategist — Claude Code skill: what it does, how to install

caching-strategist turns a vague “add caching” request into named layers, key layouts, TTL values and invalidation rules, with TypeScript samples for Redis and CDN.

MIT 278 installs ★ 64 updated 2026-01-12

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add patricio0312rev/skills --skill caching-strategist -a claude-code
Open on GitHub

What caching-strategist does

Four cache layers, each with a job. CDN serves static files and pages that change rarely. Redis holds API responses and session data. Query results get their own layer, and the browser keeps the last one. Keys are hierarchical with a version prefix, so changing one constant gives you a fresh namespace.

TTLs come as named constants, from ten seconds at the fast end to a week at the slow one. Reads go through cache-aside. Writes clear the record and the lists that depend on it, and tags handle bulk invalidation. A cron job pre-fills popular records, while a SET NX EX lock stops an expired key from firing a burst of identical queries at the database. The skill closes with a correctness checklist and an output checklist.

Every example calls a redis client: get, setex, del, sadd. Swap in another store and you keep the key layout and the checklist, but the code needs rewriting. One checklist item asks that sensitive data stay out of the cache unless it is encrypted.

What it helps with

  • pick a TTL for API responses, sessions and static files
  • lay out cache keys so a version bump clears the old set
  • drop a record and its dependent lists whenever it changes
  • keep the database from taking a burst of identical queries after a hot key expires
  • pre-fill entries for the most-read records on a schedule

Example prompts for the agent

  • Draft a Redis caching plan for our API: key names, TTLs, and what to clear when a user is updated.
  • Every time a popular key expires, the DB gets a burst of identical queries. Add stampede protection with a lock.
  • Set up a cron job that warms the cache for the most-read posts, then walk the correctness checklist.

How to install caching-strategist

1Skills CLI (Vercel)

npx skills add patricio0312rev/skills --skill caching-strategist -a claude-code

2Manually: put the files in place

~/.claude/skills/caching-strategist/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/caching-strategist/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about caching-strategist

How do I install caching-strategist in Claude Code?

Run npx skills add patricio0312rev/skills --skill caching-strategist -a claude-code. The skill file ends up at ~/.claude/skills/caching-strategist/SKILL.md.

What does caching-strategist do?

It maps out cache layers, a versioned key scheme, TTL values, invalidation triggers and stampede protection, with TypeScript examples and a correctness checklist.

Does the skill need Redis?

The samples call a redis client through get, setex, del and sadd. On a different store you still get the key layout and the checklist, but the calls have to be replaced.

Source text

SKILL.md · MIT
---
name: caching-strategist
description: Defines caching strategies with cache keys, TTL values, invalidation triggers, consistency patterns, and correctness checklist. Provides code examples for Redis, CDN, and application-level caching. Use when implementing "caching", "performance optimization", "cache strategy", or "Redis caching".
---

# Caching Strategist

Design effective caching strategies for performance and consistency.

## Cache Layers

**CDN**: Static assets, public pages (TTL: days/weeks)
**Application Cache** (Redis): API responses, sessions (TTL: minutes/hours)
**Database Cache**: Query results (TTL: seconds/minutes)
**Client Cache**: Browser/app local cache

## Cache Key Strategy

```typescript
// Hierarchical key structure
const CACHE_KEYS = {
  user: (id: string) => `user:${id}`,
  userPosts: (userId: string, page: number) => `user:${userId}:posts:${page}`,
  post: (id: string) => `post:${id}`,
  postComments: (postId: string) => `post:${postId}:comments`,
};

// Include version in keys for easy invalidation
const CACHE_VERSION = "v1";
const key = `${CACHE_VERSION}:${CACHE_KEYS.user(userId)}`;
```

## TTL Strategy

```typescript
const TTL = {
  // Frequently changing
  REALTIME: 10, // 10 seconds
  SHORT: 60, // 1 minute

  // Moderate updates
  MEDIUM: 300, // 5 minutes
  STANDARD: 3600, // 1 hour

  // Rarely changing
  LONG: 86400, // 1 day
  VERY_LONG: 604800, // 1 week
};

// Usage
await redis.setex(key, TTL.MEDIUM, JSON.stringify(data));
```

## Cache-Aside Pattern

```typescript
export const getCachedUser = async (userId: string): Promise<User> => {
  const key = CACHE_KEYS.user(userId);

  // Try cache first
  const cached = await redis.get(key);
  if (cached) {
    return JSON.parse(cached);
  }

  // Cache miss - fetch from DB
  const user = await db.users.findById(userId);

  // Store in cache
  await redis.setex(key, TTL.STANDARD, JSON.stringify(user));

  return user;
};
```

## Cache Invalidation

```typescript
// Invalidate on update
export const updateUser = async (userId: string, data: UpdateUserDto) => {
  const user = await db.users.update(userId, data);

  // Invalidate cache
  await redis.del(CACHE_KEYS.user(userId));

  // Invalidate related caches
  await redis.del(CACHE_KEYS.userPosts(userId, "*"));

  return user;
};

// Tag-based invalidation
const addCacheTags = (key: string, tags: string[]) => {
  tags.forEach((tag) => {
    redis.sadd(`cache_tag:${tag}`, key);
  });
};

const invalidateByTag = async (tag: string) => {
  const keys = await redis.smembers(`cache_tag:${tag}`);
  if (keys.length) {
    await redis.del(...keys);
    await redis.del(`cache_tag:${tag}`);
  }
};
```

## Cache Warming

```typescript
// Pre-populate cache for common queries
export const warmCache = async () => {
  const popularPosts = await db.posts.findPopular(100);

  for (const post of popularPosts) {
    const key = CACHE_KEYS.post(post.id);
    await redis.setex(key, TTL.LONG, JSON.stringify(post));
  }
};

// Schedule warming
cron.schedule("0 */6 * * *", warmCache); // Every 6 hours
```

## Cache Stampede Prevention

```typescript
// Use locks to prevent multiple simultaneous fetches
export const getCachedWithLock = async (
  key: string,
  fetchFn: () => Promise<any>
) => {
  const cached = await redis.get(key);
  if (cached) return JSON.parse(cached);

  const lockKey = `lock:${key}`;
  const acquired = await redis.set(lockKey, "1", "EX", 10, "NX");

  if (acquired) {
    try {
      // Fetch and cache
      const data = await fetchFn();
      await redis.setex(key, TTL.STANDARD, JSON.stringify(data));
      return data;
    } finally {
      await redis.del(lockKey);
    }
  } else {
    // Wait for other request to finish
    await new Promise((resolve) => setTimeout(resolve, 100));
    return getCachedWithLock(key, fetchFn);
  }
};
```

## Cache Correctness Checklist

```markdown
- [ ] Cache keys are unique and predictable
- [ ] TTL is appropriate for data freshness
- [ ] Invalidation happens on all updates
- [ ] Related caches invalidated together
- [ ] Cache stampede prevention in place
- [ ] Fallback to DB if cache fails
- [ ] Monitoring cache hit rate
- [ ] Cache size doesn't grow unbounded
- [ ] Sensitive data not cached or encrypted
- [ ] Cache warming for critical paths
```

## Best Practices

- Cache immutable data aggressively
- Short TTLs for frequently changing data
- Invalidate on write, not on read
- Monitor hit rates and adjust
- Use tags for bulk invalidation
- Prevent cache stampedes
- Graceful degradation if cache down

## Output Checklist

- [ ] Cache key naming strategy
- [ ] TTL values per data type
- [ ] Invalidation triggers documented
- [ ] Cache-aside implementation
- [ ] Stampede prevention
- [ ] Cache warming strategy
- [ ] Monitoring/metrics setup
- [ ] Correctness checklist completed

© patricio0312rev · MIT · patricio0312rev/skills

Similar skills

All skills for Backend and APIs →

From the same set148

The whole set →
monorepo-setup monorepo-setup lays out a Turborepo and pnpm monorepo: apps, shared packages, TypeScript and ESLint configs, and a build pipeline. CX Codex +1 283installs typescript-strict-migrator typescript-strict-migrator moves a TypeScript codebase to strict mode one compiler flag at a time: audit the errors, then turn on noImplicitAny, strictNullChecks and the rest. Handy when strict: true throws too much at once. CX Codex +1 280installs migration-planner migration-planner turns a database or platform move into ordered phases with feature flags, dual writes, backfill and checks, plus a way back from each step. CX Codex +1 279installs code-formatter-installer code-formatter-installer installs Prettier, ESLint, EditorConfig and git hooks, then wires them into CI so the whole team formats code the same way. CX Codex +1 278installs rest-to-graphql-migrator rest-to-graphql-migrator — a skill that walks a REST API over to GraphQL one endpoint at a time, wrapping existing routes instead of rebuilding the backend. CX Codex +1 277installs insomnia-collection-generator insomnia-collection-generator scans Express, Fastify, and Next.js routes to generate an Insomnia v4 collection export file with organized workspaces, folders, and environments. CX Codex +1 277installs security-pr-checklist-skill security-pr-checklist-skill builds a repeatable security checklist for pull requests. Use it to structure code reviews, required checks, and CI security gates. CX Codex +1 276installs design-to-component-translator The design-to-component-translator skill turns Figma specs into React components with design tokens, responsive rules, and interaction states for implementing designs in code. CX Codex +1 276installs

Project sponsors

Companies that keep this analytics open