Query Caching Strategies

Query Caching Strategies

Teaches an AI coding agent to set up query caching with Redis, Memcached and database caches, including invalidation, TTLs and cache warming.

Skill files9 files

references/

scripts/

templates/

SKILL.md93 lines
1
---
2
name: query-caching-strategies
3
description: >
4
Implement query caching strategies to improve performance. Use when setting up
5
caching layers, configuring Redis, or optimizing database query response
6
times.
7
---
8
9
# Query Caching Strategies
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 multi-level caching strategies using Redis, Memcached, and database-level caching. Covers cache invalidation, TTL strategies, and cache warming patterns.
22
23
## When to Use
24
25
- Query result caching
26
- High-read workload optimization
27
- Reducing database load
28
- Improving response time
29
- Cache layer selection
30
- Cache invalidation patterns
31
- Distributed cache setup
32
33
## Quick Start
34
35
Minimal working example:
36
37
```javascript
38
// Node.js example with Redis
39
const redis = require("redis");
40
const client = redis.createClient({
41
host: "localhost",
42
port: 6379,
43
db: 0,
44
});
45
46
// Get user with caching
47
async function getUser(userId) {
48
const cacheKey = `user:${userId}`;
49
50
// Check cache
51
const cached = await client.get(cacheKey);
52
if (cached) return JSON.parse(cached);
53
54
// Query database
55
const user = await db.query("SELECT * FROM users WHERE id = $1", [userId]);
56
57
// Cache result (TTL: 1 hour)
58
await client.setex(cacheKey, 3600, JSON.stringify(user));
59
return user;
60
}
61
62
// Cache warming on startup
63
// ... (see reference guides for full implementation)
64
```
65
66
## Reference Guides
67
68
Detailed implementations in the `references/` directory:
69
70
| Guide | Contents |
71
|---|---|
72
| [Redis Caching with PostgreSQL](references/redis-caching-with-postgresql.md) | Redis Caching with PostgreSQL |
73
| [Memcached Caching](references/memcached-caching.md) | Memcached Caching |
74
| [PostgreSQL Query Cache](references/postgresql-query-cache.md) | PostgreSQL Query Cache |
75
| [MySQL Query Cache](references/mysql-query-cache.md) | MySQL Query Cache |
76
| [Event-Based Invalidation](references/event-based-invalidation.md) | Event-Based Invalidation |
77
| [Time-Based Invalidation](references/time-based-invalidation.md) | Time-Based Invalidation, LRU Cache Eviction |
78
79
## Best Practices
80
81
### ✅ DO
82
83
- Follow established patterns and conventions
84
- Write clean, maintainable code
85
- Add appropriate documentation
86
- Test thoroughly before deploying
87
88
### ❌ DON'T
89
90
- Skip testing or validation
91
- Ignore error handling
92
- Hard-code configuration values
93

© 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…