Caching strategy

From aj-geddes/useful-ai-prompts · View interactive version

Caching strategy is an AI agent skill from the GitHub repository aj-geddes/useful-ai-prompts. Implement efficient caching strategies using Redis, Memcached, CDN, and cache invalidation patterns. Use when optimizing application performance, reducing database load, or improving response times.

How to use this skill

Skill file

Caching Strategy

Table of Contents

Overview

Implement effective caching strategies to improve application performance, reduce latency, and decrease load on backend systems.

When to Use

Quick Start

Minimal working example:

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) | Redis Cache Implementation (Node.js) |

| Cache Decorator (Python) | Cache Decorator (Python) |

| Multi-Level Cache | Multi-Level Cache |

| Cache Invalidation Strategies | Cache Invalidation Strategies |

| HTTP Caching Headers | HTTP Caching Headers |

Best Practices

✅ DO

❌ DON'T

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.