Designs comprehensive caching strategies with multiple layers, invalidation patterns, and monitoring.
You are a performance engineer who implements caching systems. Design a caching strategy for this application.
Application: [DESCRIBE APPLICATION]
Current bottlenecks: [WHAT'S SLOW]
Data characteristics:
- Read/write ratio: [RATIO]
- Data freshness needs: [REAL-TIME / MINUTES / HOURS]
- Data size: [SIZE]
Infrastructure: [REDIS / MEMCACHED / CDN / IN-MEMORY]
Scale: [CONCURRENT USERS]
Design:
**Caching Layers**
```
Browser Cache → CDN → Application Cache → Database Cache → Database
```
**Layer 1: Browser/Client Cache**
- Cache-Control headers
- ETags implementation
- Service worker caching
**Layer 2: CDN Caching**
- What to cache at edge
- Cache key design
- Purge strategy
**Layer 3: Application Cache**
```[language]
// Redis/Memcached implementation
const cache = {
async get(key) { },
async set(key, value, ttl) { },
async invalidate(pattern) { }
};
```
**Cache Key Design**
```
{namespace}:{entity}:{id}:{variant}
Example: users:profile:123:full
```
**TTL Strategy**
| Data Type | TTL | Rationale |
|-----------|-----|----------|
| User profile | 5 min | Changes rarely |
| Product list | 1 min | Updates frequently |
**Cache Invalidation**
1. Time-based expiration
2. Event-based invalidation
```[language]
// Publish invalidation event
// Subscribe and clear cache
```
3. Write-through/write-behind patterns
**Cache Patterns**
- Cache-aside (lazy loading)
- Read-through
- Write-through
- Write-behind
```[language]
// Implementation for each pattern
```
**Stampede Prevention**
- Locking mechanism
- Probabilistic early expiration
- Background refresh
**Monitoring**
- Hit/miss ratios
- Memory usage
- Eviction rates
- Latency percentiles
**Failure Handling**
- Cache unavailability
- Graceful degradation
- Circuit breaker for cacheYou are a performance engineer who implements caching systems. Design a caching strategy for this application.
Application: [DESCRIBE APPLICATION]
Current bottlenecks: [WHAT'S SLOW]
Data characteristics:
- Read/write ratio: [RATIO]
- Data freshness needs: [REAL-TIME / MINUTES / HOURS]
- Data size: [SIZE]
Infrastructure: [REDIS / MEMCACHED / CDN / IN-MEMORY]
Scale: [CONCURRENT USERS]
Design:
**Caching Layers**
```
Browser Cache → CDN → Application Cache → Database Cache → Database
```
**Layer 1: Browser/Client Cache**
- Cache-Control headers
- ETags implementation
- Service worker caching
**Layer 2: CDN Caching**
- What to cache at edge
- Cache key design
- Purge strategy
**Layer 3: Application Cache**
```[language]
// Redis/Memcached implementation
const cache = {
async get(key) { },
async set(key, value, ttl) { },
async invalidate(pattern) { }
};
```
**Cache Key Design**
```
{namespace}:{entity}:{id}:{variant}
Example: users:profile:123:full
```
**TTL Strategy**
| Data Type | TTL | Rationale |
|-----------|-----|----------|
| User profile | 5 min | Changes rarely |
| Product list | 1 min | Updates frequently |
**Cache Invalidation**
1. Time-based expiration
2. Event-based invalidation
```[language]
// Publish invalidation event
// Subscribe and clear cache
```
3. Write-through/write-behind patterns
**Cache Patterns**
- Cache-aside (lazy loading)
- Read-through
- Write-through
- Write-behind
```[language]
// Implementation for each pattern
```
**Stampede Prevention**
- Locking mechanism
- Probabilistic early expiration
- Background refresh
**Monitoring**
- Hit/miss ratios
- Memory usage
- Eviction rates
- Latency percentiles
**Failure Handling**
- Cache unavailability
- Graceful degradation
- Circuit breaker for cacheThis prompt is released under CC0 (Public Domain). You are free to use it for any purpose without attribution.
Explore similar prompts based on category and tags
Designs WebSocket real-time systems with scaling strategies, reliability features, and security considerations.
Creates comprehensive Architecture Decision Records with options analysis, decision matrices, and consequence documentation.
Conducts thorough code reviews covering security, performance, maintainability, and best practices with specific fix suggestions.
Analyzes complex error stack traces to identify root causes and provide specific code fixes.