Caching Strategy

Caching Strategy

Guides an AI agent to design caching strategies with Redis, Memcached and CDNs, covering invalidation, multi-level caches, HTTP cache headers and decorators.

Skill files8 files

references/

scripts/

templates/

SKILL.md104 lines
1
---
2
name: caching-strategy
3
description: >
4
Implement efficient caching strategies using Redis, Memcached, CDN, and cache
5
invalidation patterns. Use when optimizing application performance, reducing
6
database load, or improving response times.
7
---
8
9
# Caching Strategy
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Implement effective caching strategies to improve application performance, reduce latency, and decrease load on backend systems.
22
23
## When to Use
24
25
- Reducing database query load
26
- Improving API response times
27
- Handling high traffic loads
28
- Caching expensive computations
29
- Storing session data
30
- CDN integration for static assets
31
- Implementing distributed caching
32
- Rate limiting and throttling
33
34
## Quick Start
35
36
Minimal working example:
37
38
```typescript
39
import Redis from "ioredis";
40
41
interface CacheOptions {
42
ttl?: number; // Time to live in seconds
43
prefix?: string;
44
}
45
46
class CacheService {
47
private redis: Redis;
48
private defaultTTL = 3600; // 1 hour
49
50
constructor(redisUrl: string) {
51
this.redis = new Redis(redisUrl, {
52
retryStrategy: (times) => {
53
const delay = Math.min(times * 50, 2000);
54
return delay;
55
},
56
maxRetriesPerRequest: 3,
57
});
58
59
this.redis.on("connect", () => {
60
console.log("Redis connected");
61
});
62
63
this.redis.on("error", (error) => {
64
// ... (see reference guides for full implementation)
65
```
66
67
## Reference Guides
68
69
Detailed implementations in the `references/` directory:
70
71
| Guide | Contents |
72
|---|---|
73
| [Redis Cache Implementation (Node.js)](references/redis-cache-implementation-nodejs.md) | Redis Cache Implementation (Node.js) |
74
| [Cache Decorator (Python)](references/cache-decorator-python.md) | Cache Decorator (Python) |
75
| [Multi-Level Cache](references/multi-level-cache.md) | Multi-Level Cache |
76
| [Cache Invalidation Strategies](references/cache-invalidation-strategies.md) | Cache Invalidation Strategies |
77
| [HTTP Caching Headers](references/http-caching-headers.md) | HTTP Caching Headers |
78
79
## Best Practices
80
81
### ✅ DO
82
83
- Set appropriate TTL values
84
- Implement cache warming for critical data
85
- Use cache-aside pattern for reads
86
- Monitor cache hit rates
87
- Implement graceful degradation on cache failure
88
- Use compression for large cached values
89
- Namespace cache keys properly
90
- Implement cache stampede prevention
91
- Use consistent hashing for distributed caching
92
- Monitor cache memory usage
93
94
### ❌ DON'T
95
96
- Cache everything indiscriminately
97
- Use caching as a fix for poor database design
98
- Store sensitive data without encryption
99
- Forget to handle cache misses
100
- Set TTL too long for frequently changing data
101
- Ignore cache invalidation strategies
102
- Cache without monitoring
103
- Store large objects without consideration
104

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…