caching-strategy — Claude Code skill: Redis and CDN caching
Walks your agent through cache design: Redis, Memcached, CDN and invalidation. Useful when repeated queries drag response times down.
npx skills add aj-geddes/useful-ai-prompts --skill caching-strategy -a claude-codeWhat caching-strategy does
The skill lays out working cache patterns and points at the places they break. It ships a short ioredis service example with a 3600-second default TTL, retry backoff and error handling, plus reference guides under references/: a Node.js cache implementation, a Python cache decorator, multi-level caching, invalidation strategies and HTTP cache headers.
House rules come with it. Set sensible TTLs, warm critical data, use cache-aside for reads, watch hit rates, degrade gracefully when the cache dies, namespace your keys, guard against stampede. The don't list is just as blunt: no caching everything, no papering over a bad schema, no unencrypted sensitive values, no long TTLs on data that changes often.
The inline example stops early and defers to the reference guides, so you still need a running Redis at the URL you hand the constructor. Nothing in the sample connects without it.
What it helps with
- cut database load from repeated queries
- speed up API responses with a cache layer
- pick an invalidation strategy that avoids stale reads
- build a multi-level cache with a CDN for static assets
- survive a stampede when a hot key expires
Example prompts for the agent
- Cache the API responses in Redis with a 600 second TTL and a per-service key prefix
- Show me how to invalidate the product cache after a database update
- Set up a two-level cache: in-process memory plus Redis
How to install caching-strategy
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill caching-strategy -a claude-code2Manually: put the files in place
~/.claude/skills/caching-strategy/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/caching-strategy/
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill caching-strategy -a codex2Manually: put the files in place
.agents/skills/caching-strategy/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill caching-strategy -a cursor2Manually: put the files in place
.cursor/skills/caching-strategy/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install aj-geddes/useful-ai-prompts caching-strategy2Manually: put the files in place
.github/skills/caching-strategy/SKILL.md1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill caching-strategy -a gemini-cli2Platform CLI
gemini skills install https://github.com/aj-geddes/useful-ai-prompts --path skills/caching-strategyManually: put the files in place
.devin/skills/caching-strategy/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill caching-strategy -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about caching-strategy
How do I install caching-strategy in Claude Code?
Run npx skills add aj-geddes/useful-ai-prompts --skill caching-strategy -a claude-code. The skill lands in ~/.claude/skills/caching-strategy/SKILL.md.
What does caching-strategy do?
It gives the agent ready cache patterns for Redis, Memcached and CDN work, along with invalidation approaches. Reference guides cover Node.js and Python implementations.
What do I need for the example to run?
The ioredis sample connects to Redis at the URL you pass in. You need a running Redis instance and the ioredis package installed.
Source text
SKILL.md · MIT
---
name: caching-strategy
description: >
Implement efficient caching strategies using Redis, Memcached, CDN, and cache
invalidation patterns. Use when optimizing application performance, reducing
database load, or improving response times.
---
# Caching Strategy
## Table of Contents
- [Overview](#overview)
- [When to Use](#when-to-use)
- [Quick Start](#quick-start)
- [Reference Guides](#reference-guides)
- [Best Practices](#best-practices)
## Overview
Implement effective caching strategies to improve application performance, reduce latency, and decrease load on backend systems.
## When to Use
- Reducing database query load
- Improving API response times
- Handling high traffic loads
- Caching expensive computations
- Storing session data
- CDN integration for static assets
- Implementing distributed caching
- Rate limiting and throttling
## Quick Start
Minimal working example:
```typescript
import Redis from "ioredis";
interface CacheOptions {
ttl?: number; // Time to live in seconds
prefix?: string;
}
class CacheService {
private redis: Redis;
private defaultTTL = 3600; // 1 hour
constructor(redisUrl: string) {
this.redis = new Redis(redisUrl, {
retryStrategy: (times) => {
const delay = Math.min(times * 50, 2000);
return delay;
},
maxRetriesPerRequest: 3,
});
this.redis.on("connect", () => {
console.log("Redis connected");
});
this.redis.on("error", (error) => {
// ... (see reference guides for full implementation)
```
## Reference Guides
Detailed implementations in the `references/` directory:
| Guide | Contents |
|---|---|
| [Redis Cache Implementation (Node.js)](references/redis-cache-implementation-nodejs.md) | Redis Cache Implementation (Node.js) |
| [Cache Decorator (Python)](references/cache-decorator-python.md) | Cache Decorator (Python) |
| [Multi-Level Cache](references/multi-level-cache.md) | Multi-Level Cache |
| [Cache Invalidation Strategies](references/cache-invalidation-strategies.md) | Cache Invalidation Strategies |
| [HTTP Caching Headers](references/http-caching-headers.md) | HTTP Caching Headers |
## Best Practices
### ✅ DO
- Set appropriate TTL values
- Implement cache warming for critical data
- Use cache-aside pattern for reads
- Monitor cache hit rates
- Implement graceful degradation on cache failure
- Use compression for large cached values
- Namespace cache keys properly
- Implement cache stampede prevention
- Use consistent hashing for distributed caching
- Monitor cache memory usage
### ❌ DON'T
- Cache everything indiscriminately
- Use caching as a fix for poor database design
- Store sensitive data without encryption
- Forget to handle cache misses
- Set TTL too long for frequently changing data
- Ignore cache invalidation strategies
- Cache without monitoring
- Store large objects without consideration
© aj-geddes · MIT · aj-geddes/useful-ai-prompts