Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add aj-geddes/useful-ai-prompts --skill caching-strategy -a claude-code
Open on GitHub

What 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-code

2Manually: put the files in place

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

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

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

Similar skills

All skills for Backend and APIs →

From the same set149

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor