LazyLayersv0.5.3

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

The three parts

PartWhat it does
L1Keeps encoded values in this process, with LRU eviction and memory bounds
L2Shares cached values in Redis, so another instance can reuse a loaded value
Event busSends 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

TaskRead
Check runtime, modules, or TypeScript requirementsInstallation
Deploy a service with RedisProduction setup
Set memory and freshness limitsConfiguration
Handle slow loaders or dependency failuresFailure handling
Inspect entries, events, and metricsObservability
Coordinate a durable payment or order attemptTransaction 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

On this page