Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
aj-geddes avatar

Query Caching Strategies

  • 413 installs
  • 305 repo stars
  • Updated March 4, 2026
  • aj-geddes/useful-ai-prompts

query-caching-strategies is an agent skill that designs Redis, CDN, and in-process cache layers with TTL and invalidation rules for developers who need to reduce database load on read-heavy APIs.

About

query-caching-strategies is an aj-geddes/useful-ai-prompts agent skill for implementing multi-level query caching on high-read backend paths. The skill walks through cache-aside and write-through patterns, TTL selection, cache warming, and invalidation strategies using Redis, Memcached, CDN edge caches, and database-level caches. A Node.js quick-start shows Redis setex with a 3600-second TTL around PostgreSQL user lookups, and six reference guides cover Redis with PostgreSQL, Memcached, PostgreSQL query cache, MySQL query cache, event-based invalidation, and time-based invalidation with LRU eviction. Developers reach for query-caching-strategies when API response times spike under read load, when choosing between Redis and CDN caching, or when defining invalidation rules after writes.

  • Cache-aside vs write-through selection
  • TTL and stampede mitigation patterns
  • Invalidation triggers tied to data mutations
  • Redis vs CDN vs application cache fit
  • Observability hooks for hit rate and staleness

Query Caching Strategies by the numbers

  • 413 all-time installs (skills.sh)
  • Ranked #142 of 911 Databases skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill query-caching-strategies

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs413
repo stars305
Last updatedMarch 4, 2026
Repositoryaj-geddes/useful-ai-prompts

How do you cache database queries with Redis?

Choose Redis, CDN, or in-process caches, define TTL and invalidation rules, and design cache-aside or write-through patterns to cut database load on high-traffic read paths.

Who is it for?

Backend developers optimizing read-heavy Node.js or SQL APIs that need Redis, Memcached, or CDN caching with explicit invalidation.

Skip if: Developers solving a one-off slow query who only need a single SQL index without a broader cache layer design.

When should I use this skill?

Setting up Redis or CDN caching, tuning TTL and invalidation, or reducing database load on high-traffic read endpoints.

What you get

Cache key conventions, TTL policies, invalidation rules, and reference-backed Redis or Memcached integration patterns.

  • cache key schema
  • TTL and invalidation policy
  • cache-aside integration code

By the numbers

  • Bundles 6 reference guides for Redis, Memcached, PostgreSQL, MySQL, and invalidation patterns
  • Quick-start example uses Redis setex with a 3600-second TTL

Files

SKILL.mdMarkdownGitHub ↗

Query Caching Strategies

Table of Contents

Overview

Implement multi-level caching strategies using Redis, Memcached, and database-level caching. Covers cache invalidation, TTL strategies, and cache warming patterns.

When to Use

  • Query result caching
  • High-read workload optimization
  • Reducing database load
  • Improving response time
  • Cache layer selection
  • Cache invalidation patterns
  • Distributed cache setup

Quick Start

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)

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Redis Caching with PostgreSQLRedis Caching with PostgreSQL
Memcached CachingMemcached Caching
PostgreSQL Query CachePostgreSQL Query Cache
MySQL Query CacheMySQL Query Cache
Event-Based InvalidationEvent-Based Invalidation
Time-Based InvalidationTime-Based Invalidation, LRU Cache Eviction

Best Practices

✅ DO

  • Follow established patterns and conventions
  • Write clean, maintainable code
  • Add appropriate documentation
  • Test thoroughly before deploying

❌ DON'T

  • Skip testing or validation
  • Ignore error handling
  • Hard-code configuration values

Related skills

How it compares

Use query-caching-strategies for multi-layer cache design and invalidation policy; use a database-indexing skill when the bottleneck is query plans, not repeated reads.

FAQ

Which cache backends does query-caching-strategies cover?

query-caching-strategies covers Redis, Memcached, CDN edge caches, PostgreSQL query cache, and MySQL query cache. Six reference guides provide database-specific caching and invalidation patterns for each stack.

What caching patterns does the skill teach?

query-caching-strategies teaches cache-aside, write-through, cache warming, TTL strategies, event-based invalidation, time-based invalidation, and LRU eviction. The quick-start uses Redis setex with a 3600-second TTL around SQL reads.

Databasesdatabasesanalytics

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.