cacheable-js

Implements L1/L2 caching conventions for the Cacheable and Keyv ecosystem in Node.js.

2|Updated May 16, 2026
One-click install
npx skills add https://github.com/avbel/ai-skills --skill cacheable-js-avbel
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cacheable-js
Source: https://github.com/avbel/ai-skills/tree/main/skills/cacheable-js
Command: npx skills add https://github.com/avbel/ai-skills --skill cacheable-js-avbel

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Node.js developers using the Cacheable ecosystem often misuse TTL semantics, stale API patterns, or misconfigure L1/L2 stores, tags, and distributed sync, leading to subtle caching bugs in production. ## Core Features & Use Cases - L1/L2 Cache Setup: Configures Cacheable with memory primary and Redis/Valkey secondary stores, including TTL shorthand, maxTtl caps, and nonBlocking modes. - Cache Patterns: Covers wrap/memoize, getOrSet cache-aside, tag-based invalidation, hooks, events, and instance statistics. - Ecosystem Guidance: Provides package selection across cacheable, cache-manager, @cacheable/memory, and Keyv storage adapters, plus production pitfalls like undefined misses and shared-store clear() hazards. - Use Case: When adding Redis-backed caching to an Express or NestJS service, use this Skill to generate correct Cacheable configuration with tag invalidation and error event handling. ## Quick Start Ask the AI to set up a Cacheable instance with in-memory L1 and Redis L2 storage including TTL defaults and tag invalidation for your Node.js service.

Frequently Asked Questions about cacheable-js

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

FAQPage Schema
How do I set up L1/L2 caching with Cacheable and Redis?▼

Create a Cacheable instance with a Keyv primary using CacheableMemory and a secondary from @keyv/redis's createKeyv. Set default ttl, maxTtl, and a namespace so reads promote L2 hits into L1 automatically.

What is the difference between cacheable and cache-manager?▼

Cacheable provides full L1/L2 caching with hooks, events, stats, tags, and sync, while cache-manager targets NestJS compatibility with a simpler multi-store API. Both return undefined on cache misses in current versions.

How does tag-based cache invalidation work in Cacheable?▼

Enable tags: true on every instance sharing the store, then pass tags when calling set or setMany. Invalidate entries with cache.tags.invalidateTag, with tag metadata stored in the shared secondary store for cross-instance visibility.

Does Cacheable support distributed cache synchronization?▼

Yes, Cacheable supports distributed sync through a Qified message provider such as RedisMessageProvider. Sync updates only the primary storage of peer instances and is eventually consistent, so each service should use its own namespace.

Why does my cache get return undefined instead of null?▼

Cacheable and cache-manager v7 return undefined on cache misses by design. Avoid storing null sentinels and check for undefined explicitly when handling misses in application code.

When should I use wrap versus getOrSet for caching?▼

Use wrap to memoize a function across many call sites with a key prefix or custom key serializer. Use getOrSet for cache-aside reads where you load a single key on demand with a TTL.