Introduction
Add read-through caching to a Node.js service, then share values and invalidations across instances.
LazyLayers is a cache for Node.js services. Your application reads with getOrSet, supplies a loader for misses, and invalidates cached values after database writes.
Start with L1 in one process. Add Redis L2 and an event bus when several instances need to share values and receive invalidations. setupCache configures the layers, waits for readiness, and provides managed cleanup.
These docs cover 0.5.3, released on npm. See the release notes for changes and the Redis store reference before upgrading an existing Redis namespace.
Start here
Run your first cache
Run a local example, connect Redis, and invalidate after a write.
Follow one key
See what happens on a miss, a cache hit, an update, and an outage.
The three parts
| Part | What it does |
|---|---|
| L1 | Keeps encoded values in this process, with LRU eviction and memory bounds |
| L2 | Shares cached values in Redis, so another instance can reuse a loaded value |
| Event bus | Sends invalidations and eligible loader results to peer instances |
In-flight dedupe shares same-key loader work within a process. Redis leases coordinate loads across instances. A successful loader can prime peer L1 caches when delivery, payload size, and memory admission allow it.
The database remains the source of truth. Cache events can be delayed or missed, and a cache lease does not guarantee exactly-once execution. Use caching for reads that tolerate the configured freshness and failure behavior.
Choose the page for your task
| Task | Read |
|---|---|
| Check runtime, modules, or TypeScript requirements | Installation |
| Deploy a service with Redis | Production setup |
| Set memory and freshness limits | Configuration |
| Handle slow loaders or dependency failures | Failure handling |
| Inspect entries, events, and metrics | Observability |
| Coordinate a durable payment or order attempt | Transaction coordination |
Transaction coordination is an opt-in API under lazy-layers-cache/transactions. It uses an authoritative Redis primary and application-owned durable state, separately from L1/L2 caching.
Where to next
- Quickstart gets a cache running with a copyable example.
- API reference lists methods, signatures, and return values.
- Learn the system design gives you a focused path through the concepts.