Agent skill

caching-strategy

Implement efficient caching strategies using Redis, Memcached, CDN, and cache invalidation patterns. Use when optimizing application performance, reducing database load, or improving response times.

Stars 151
Forks 20

Install this agent skill to your Project

npx add-skill https://github.com/aj-geddes/useful-ai-prompts/tree/main/skills/caching-strategy

SKILL.md

Caching Strategy

Table of Contents

  • Overview
  • When to Use
  • Quick Start
  • Reference Guides
  • 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) 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

  • 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

Expand your agent's capabilities with these related and highly-rated skills.

aj-geddes/useful-ai-prompts

websocket-implementation

Implement real-time bidirectional communication with WebSockets including connection management, message routing, and scaling. Use when building real-time features, chat systems, live notifications, or collaborative applications.

151 20
Explore
aj-geddes/useful-ai-prompts

refactor-legacy-code

Modernize and improve legacy codebases while maintaining functionality. Use when you need to refactor old code, reduce technical debt, modernize deprecated patterns, or improve code maintainability without breaking existing behavior.

151 20
Explore
aj-geddes/useful-ai-prompts

Sentiment Analysis

Classify text sentiment using NLP techniques, lexicon-based analysis, and machine learning for opinion mining, brand monitoring, and customer feedback analysis

151 20
Explore
aj-geddes/useful-ai-prompts

flask-api-development

Develop lightweight Flask APIs with routing, blueprints, database integration, authentication, and request/response handling. Use when building RESTful APIs, microservices, or lightweight web services with Flask.

151 20
Explore
aj-geddes/useful-ai-prompts

ML Model Explanation

Interpret machine learning models using SHAP, LIME, feature importance, partial dependence, and attention visualization for explainability

151 20
Explore
aj-geddes/useful-ai-prompts

Statistical Hypothesis Testing

Conduct statistical tests including t-tests, chi-square, ANOVA, and p-value analysis for statistical significance, hypothesis validation, and A/B testing

151 20
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results