Default
S3-FIFO
New keys wait in a small queue. Only keys read again move to the main queue, and recently evicted keys are remembered as ghosts. Best mean miss ratio in our policy matrix.
Introducing LazyLayers 8.0. Faster reads, fewer Redis round trips, and more control over memory.
Explore what’s newLazyLayers Intelligent evictionUpdated
Give the L1 a byte budget and pick an eviction policy. When the heap or the container gets close to its limit, the cache gives memory back on its own: stale fail-safe copies first, then whatever your policy values least.
Limits
Values are charged their real size: the exact encoded bytes by default, or a model of V8’s object layout in reference mode, within 3% of measured heap use on the shapes we test.
const cache = new LazyLayersCache({
levels: {
L1: {
maxEntries: 50_000,
maxMemory: '256MB', // or '10%' of effective memory
policy: 's3fifo', // 'lru' | 'sieve' | 'fifo'
valueMode: 'encoded', // 'reference' skips the copy
},
},
})
Eviction policies
On skewed traffic (Zipf α = 1.0, 100,000 keys, cache at 10%), S3-FIFO kept 78.23% hits, against 76.64% for quick-lru and 73.59% for lru-cache.
Default
New keys wait in a small queue. Only keys read again move to the main queue, and recently evicted keys are remembered as ghosts. Best mean miss ratio in our policy matrix.
Simple, scan-resistant
One queue and a moving hand that skips recently used entries. 78.0% hits on the skewed workload.
Familiar
Evicts the least recently used entry. Good when recent use predicts the next read.
Cheapest
Evicts in insertion order, with no bookkeeping on reads.
Memory pressure
A shared budget samples memory every five seconds and on writes. With nothing configured, a process nearing its container limit makes the cache shrink.
Pressure at 85% of the heap limit, critical at 95%.
Pressure at 90% of maxProcessMemory, which defaults to the container limit or host memory, so Buffers outside the heap count too.
maxMemory above 75% of effective memory is lowered to 75%, with a warning.
Under sustained pressure the target drops to 90% of what the caches hold per sample, 70% when critical. Stale fail-safe copies go first.
On Cloudflare Workers the isolate L1 is a separate, smaller store bounded by entry count. See Cloudflare limits.
On the policy matrix in BENCHMARKS.md it had the lowest mean miss ratio of the built-in policies, missed up to 14.18 points less than LRU, and was never more than 4.45 points behind it. Choose lru when the whole popular set is replaced at once and fits in the cache.
On Zipf α = 1.0 traffic over 100,000 keys with room for 10% of them, the in-memory store hit 78.23% with S3-FIFO, against 76.64% for quick-lru, which holds up to twice its configured size, and 73.59% for lru-cache.
Encoded, the default, stores bytes and decodes a private copy on every hit, so callers cannot change each other’s values. A warm L1 get() measured 1,141 ns. Reference mode stores the object and returns it, 120 ns in the same benchmark. Use it when callers treat values as read-only.
In BENCHMARKS.md, 100,000 small entries retained 76.1 bytes each in encoded mode with LRU and 98.4 with S3-FIFO. Reference mode retained 74.5 and 96.8, and lru-cache 57.1. The difference is the expiry time, charged bytes and payload size each LazyLayers entry keeps, and S3-FIFO’s queue state.