Getting Started
Installation
Basic Setup
The simplest cache stack uses a single memory layer:
Reading Through the Cache
Use the read-through pattern to fetch data with automatic caching:
Multi-Layer Setup
For production, add Redis for cross-process sharing:
Use rediss:// Redis URLs for production CLI operations and hosted Redis endpoints. The CLI rejects plaintext redis:// URLs under NODE_ENV=production unless you explicitly pass --allow-plaintext.
How Layered Reads Work
When you call cache.get():
- L1 Memory is checked first (~0.01ms)
- If missing, L2 Redis is checked (~0.5ms)
- If also missing, your fetcher runs (~20ms+)
- On any partial hit, upper layers are backfilled automatically
Three-Layer Setup with Disk Persistence
Add disk persistence for fault tolerance:
Key Configuration Options
MemoryLayer
RedisLayer
DiskLayer
Common Patterns
Function Wrapping
Transparently cache any function with wrap():
Namespacing
Create scoped cache views with prefixes:
Bulk Operations
Set and get multiple keys efficiently:
Next Steps
- Tutorial — Learn stampede prevention, tag invalidation, and more
- API Reference — Complete method documentation
- Integrations — Use with Express, Fastify, NestJS, and more