Introduction
Add read-through caching to Node.js or Cloudflare Workers, with Redis or Cloudflare KV as L2.
LazyLayers is a cache for Node.js services and Cloudflare Workers. 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 or Cloudflare KV as shared L2. Node.js can use an event bus to fan out invalidations. Cloudflare Workers can publish application invalidations to a Queue for retryable KV deletion. setupCache configures the Node.js layers, waits for readiness, and provides managed cleanup.
These docs describe the 0.6.3 release. Review the Redis store reference when 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 through Redis or Cloudflare KV |
| Event bus | On Node.js, 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 |
| Use Cloudflare KV from Workers or Node.js | Cloudflare KV system design |
| 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.