query-caching-strategies by aj-geddes/useful-ai-prompts
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill query-caching-strategies使用 Redis、Memcached 和数据库级缓存实现多级缓存策略。涵盖缓存失效、TTL 策略和缓存预热模式。
最小工作示例:
// Node.js example with Redis
const redis = require("redis");
const client = redis.createClient({
host: "localhost",
port: 6379,
db: 0,
});
// Get user with caching
async function getUser(userId) {
const cacheKey = `user:${userId}`;
// Check cache
const cached = await client.get(cacheKey);
if (cached) return JSON.parse(cached);
// Query database
const user = await db.query("SELECT * FROM users WHERE id = $1", [userId]);
// Cache result (TTL: 1 hour)
await client.setex(cacheKey, 3600, JSON.stringify(user));
return user;
}
// Cache warming on startup
// ... (see reference guides for full implementation)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
references/ 目录下的详细实现:
| 指南 | 内容 |
|---|---|
| Redis Caching with PostgreSQL | Redis 与 PostgreSQL 缓存 |
| Memcached Caching | Memcached 缓存 |
| PostgreSQL Query Cache | PostgreSQL 查询缓存 |
| MySQL Query Cache | MySQL 查询缓存 |
| Event-Based Invalidation | 基于事件的失效 |
| Time-Based Invalidation | 基于时间的失效,LRU 缓存淘汰 |
每周安装数
126
仓库
GitHub 星标数
126
首次出现
2026年1月21日
安全审计
安装于
opencode102
gemini-cli100
codex98
cursor96
claude-code93
github-copilot86
Implement multi-level caching strategies using Redis, Memcached, and database-level caching. Covers cache invalidation, TTL strategies, and cache warming patterns.
Minimal working example:
// Node.js example with Redis
const redis = require("redis");
const client = redis.createClient({
host: "localhost",
port: 6379,
db: 0,
});
// Get user with caching
async function getUser(userId) {
const cacheKey = `user:${userId}`;
// Check cache
const cached = await client.get(cacheKey);
if (cached) return JSON.parse(cached);
// Query database
const user = await db.query("SELECT * FROM users WHERE id = $1", [userId]);
// Cache result (TTL: 1 hour)
await client.setex(cacheKey, 3600, JSON.stringify(user));
return user;
}
// Cache warming on startup
// ... (see reference guides for full implementation)
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Redis Caching with PostgreSQL | Redis Caching with PostgreSQL |
| Memcached Caching | Memcached Caching |
| PostgreSQL Query Cache | PostgreSQL Query Cache |
| MySQL Query Cache | MySQL Query Cache |
| Event-Based Invalidation | Event-Based Invalidation |
| Time-Based Invalidation | Time-Based Invalidation, LRU Cache Eviction |
Weekly Installs
126
Repository
GitHub Stars
126
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode102
gemini-cli100
codex98
cursor96
claude-code93
github-copilot86
Supabase 使用指南:安全最佳实践、CLI 命令与 MCP 服务器配置
3,600 周安装