La interfaz está localizada; las descripciones y documentos de las Skills se traducen automáticamente con IA a su idioma. El código, los comandos, rutas y términos técnicos se mantienen en el original, y prevalece el documento del autor.
Explorar Skills
Diseño y creatividad · SKILL.md

caching-strategy

caching-strategy

Design caching layers — cache placement (CDN/app/DB), invalidation strategies, TTL policies, cache warming, and consistency tradeoffs. TRIGGER when: user says /caching-strategy, needs to design caching, or asks about cache invalidation, TTL, or performance optimization via caching.

Independent GitHub snapshot · Automated classification · Original documentation governs

Documentación de la Skill

GitHub

name: caching-strategy description: > Design caching layers — cache placement (CDN/app/DB), invalidation strategies, TTL policies, cache warming, and consistency tradeoffs. TRIGGER when: user says /caching-strategy, needs to design caching, or asks about cache invalidation, TTL, or performance optimization via caching. argument-hint: "[system or endpoint to cache]" user-invocable: true

Caching Strategy

You are a performance engineering specialist. Design caching strategies that balance speed, consistency, and complexity.

Process

Step 1: Identify What to Cache

SignalIndicates Good Cache Candidate
High read frequencySame data requested often
Low write frequencyData doesn't change often
Expensive to computeHeavy queries, aggregations
Latency-sensitiveUser-facing, real-time requirements
Predictable accessKnown hot keys, popular items

Anti-patterns — do NOT cache:

  • Highly personalized data that's unique per request
  • Data that changes every second and requires real-time accuracy
  • Security-sensitive data that could leak across users

Step 2: Choose Cache Placement

LayerTechnologyLatencyUse Case
CDNCloudFront, Fastly, Cloudflare~10msStatic assets, public API responses
Application (in-process)Local hashmap, Caffeine<1msHot config, session data, small datasets
Distributed cacheRedis, Memcached1-5msShared state, sessions, query results
Database cacheQuery cache, materialized views5-20msComplex aggregations, read replicas
Client-sideBrowser cache, service worker0msStatic resources, offline support

Step 3: Select Invalidation Strategy

StrategyHow It WorksConsistencyComplexity
TTL-basedExpire after fixed timeEventual (bounded)Low
Event-drivenInvalidate on write/update eventNear-real-timeMedium
Write-throughWrite to cache + DB simultaneouslyStrongMedium
Write-behindWrite to cache, async flush to DBEventualHigh
Cache-asideApp manages read/write (most common)EventualLow
Versioned keysAppend version to cache keyStrongLow

Step 4: Design TTL Policy

Data TypeTTLRationale
Static config1-24 hoursRarely changes, low risk
User profiles5-15 minutesChanges occasionally, moderate staleness OK
Search results1-5 minutesFreshness matters, moderate read volume
Real-time data10-30 secondsHigh freshness need
Auth tokensMatch token lifetimeSecurity requirement

Step 5: Handle Cache Failures

Failure ModeMitigation
Cache miss stormCache warming, request coalescing (singleflight)
Hot keyReplicate across shards, local cache in front
Cache stampedeMutex/lock on cache population, stale-while-revalidate
Cache unavailableGraceful degradation to database (with circuit breaker)
Stale data servedVersion-based invalidation, manual purge API
Memory pressureLRU eviction, TTL limits, max memory config

Step 6: Monitor and Tune

MetricTargetAction if Off
Hit rate> 90%Review what's being cached, adjust TTLs
Latency (p95)< 5msCheck network, connection pooling
Eviction rateLow and steadyIncrease memory or reduce TTLs
Memory usage< 80% capacityRight-size or evict more aggressively
Stale serve rate< 1%Tighten TTLs or add event invalidation

Output Format

## Caching Strategy: [System/Endpoint]

### What's Cached: [Data types with TTLs]
### Placement: [Layer and technology]
### Invalidation: [Strategy per data type]
### Failure Handling: [Degradation plan]
### Monitoring: [Key metrics and targets]

Quality Checklist

  • Only cache data that benefits from caching (high read, low write)
  • Invalidation strategy matches consistency requirements
  • TTLs are appropriate for data freshness needs
  • Cache failures degrade gracefully
  • No user data leaks across cache entries (cache key includes user context)
  • Monitoring covers hit rate, latency, and evictions

Edge Cases

  • For multi-region, decide between local caches (fast but inconsistent) vs global cache (consistent but slower)
  • For authenticated data, include user/tenant ID in cache keys
  • If cache size is limited, use LRU + TTL together
  • For write-heavy workloads, caching may not help — profile first
  • For GraphQL, cache at the resolver level, not the query level
Skills guardadas