hm-nodejs-cache

Implements Redis cache-aside patterns with ioredis in Fastify Node.js services.

Updated Apr 26, 2026
One-click install
npx skills add https://github.com/ArkhiMuttaqina/publisher-for-campuss --skill hm-nodejs-cache-arkhimuttaqina
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: hm-nodejs-cache
Source: https://github.com/ArkhiMuttaqina/publisher-for-campuss/tree/main/skills/hm-nodejs-cache
Command: npx skills add https://github.com/ArkhiMuttaqina/publisher-for-campuss --skill hm-nodejs-cache-arkhimuttaqina

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires ioredis, fastify-plugin.

What problem does it solve? Node.js services that query the database on every request suffer from unnecessary load and slow response times. This Skill provides a complete pattern for adding Redis caching to a Fastify application, covering connection setup, cache-aside reads, TTL strategies, and safe invalidation on mutations. ## Core Features & Use Cases - Redis Fastify Plugin: Register a single shared ioredis connection as a Fastify decorator with retry strategy, error logging, and graceful shutdown. - Typed Cache Helper: A namespaced cache utility with get, set, del, SCAN-based pattern deletion, and a getOrSet method implementing cache-aside in one call. - TTL & Key Design Guidance: Recommended TTLs per resource type (single resource, lists, sessions, config) and predictable namespaced key patterns. - Use Case: An orders service caches getById lookups for 5 minutes, caches filtered list queries for 1 minute, and invalidates the cache entry after every update or delete so stale data is never served. ## Quick Start Add Redis caching to my Fastify order service using ioredis with the cache-aside pattern and proper TTLs.

Frequently Asked Questions about hm-nodejs-cache

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement the cache-aside pattern in Node.js?▼

Check the cache first, and on a miss read from the database, write the result to Redis with a TTL, then return it. The getOrSet helper in this Skill wraps this flow in a single typed method using ioredis.

How do I use ioredis with Fastify?▼

Register ioredis inside a fastify-plugin wrapped plugin and expose it via fastify.decorate so all routes share one connection. Add an onClose hook that calls redis.quit() for graceful shutdown.

Why should I use SCAN instead of KEYS in Redis?▼

KEYS blocks Redis's single-threaded event loop on large keyspaces, stalling all other commands. SCAN iterates incrementally in batches, so pattern-based deletion via scanStream is safe for production workloads.

What TTL should I set for cached data in Redis?▼

Use about 300 seconds for single resources, 60 seconds for list or search results, 900 seconds for sessions, and 3600 seconds for rarely changing config data. Always set a TTL to prevent unbounded memory growth.

Should I update or delete the cache after a database mutation?▼

Invalidate (delete) the cache entry after any create, update, or delete rather than updating it. Deleting avoids race conditions and stale data; the next read repopulates the cache from the database.