‹ 首页

caching-strategy

@aj-geddes · 收录于 5 天前 · 上游提交 4 个月前

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

适合你,如果应用响应慢、数据库负载高,需要引入缓存方案

/ 通过 npx 安装 校验哈希
npx oh-my-skill add aj-geddes/useful-ai-prompts/caching-strategy
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- aj-geddes/useful-ai-prompts/caching-strategy
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify aj-geddes/useful-ai-prompts/caching-strategy
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
300GitHub stars
~521最小装载
~3.3K含声明引用
~3.5K文本包总量
索引托管

怎么用

商店整理自技能原文 · 版本 3f5182c · 表述以原文为准
它做什么

安装后,Claude 能帮你用 Redis、Memcached、CDN 等工具实现缓存策略,提升应用性能、减少数据库负载和延迟。

什么时候触发

当你要求优化性能、减少数据库查询负载、改善 API 响应时间,或实现缓存相关功能时触发。

装好后可以这样说
Claude 将生成 Redis 缓存服务代码。
Claude 会提供 CDN 缓存配置指南。
Claude 将解释多种失效模式。
技能原文 SKILL.md作者撰写 · MIT · 3f5182c

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:

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
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。