Compared with other caches
How lazy-layers-cache compares with bentocache, cache-manager, cacheable, cachified, async-cache-dedupe, layered-loader and lru-cache: features from each README, and measured results.
lazy-layers-cache and bentocache are both multi-tier caches for Node.js: an in-memory L1 in front of a shared L2, getOrSet read-through, and a bus that keeps other instances' L1 in sync. Read from each library's own README, lazy-layers-cache also coordinates one load per key across processes with a Redis lease, wakes waiting servers when that load finishes, limits L1 by bytes and gives memory back under process pressure, and runs on Cloudflare Workers. bentocache ships more storage drivers: Redis, Upstash, SQL, DynamoDB, file and Vercel KV.
Every number on this page comes from BENCHMARKS.md, which has every table, the command that produced it, and the raw data. The timings were measured on 2026-11-12 on an Apple M5 (10 logical CPUs) with Node 24.21: each library at a pinned version, configured as its documentation shows, each measurement in a fresh process, median of 5 runs. They cover in-process behaviour only; Redis over a real network and many instances under load are not measured yet.
Read-through caches, measured
| Library | Setting | Warm hit, ns per call | 10,000 callers on one cold key, ms | Skewed traffic, ns per call · hit ratio |
|---|---|---|---|---|
| lazy-layers-cache 8.0.0 | reference, SIEVE | 180 | 30.2 | 2,011 · 75.41% |
| lazy-layers-cache 8.0.0 | encoded, LRU | 1,504 | 31.0 | 4,021 · 72.85% |
| layered-loader 17.0.0 | Loader with in-memory cache | 220 | 25.6 | 435 · 72.85% |
| async-cache-dedupe 3.4.0 | defined function, memory storage | 658 | 25.1 | 911 · 72.85% |
| @epic-web/cachified 5.6.3 | lru-cache store | 821 | 45.1 | 1,150 · 72.85% |
| bentocache 1.6.1 | memory driver, serialize: false | 1,120 | 89.8 | 1,936 · 72.85% |
| bentocache 1.6.1 | memory driver, default (serialized) | 2,429 | 114 | 3,640 · 72.85% |
| cache-manager 7.2.9 | wrap, Keyv in-memory store | 9,337 | 35.6 | 10,635 · 72.85% |
| cacheable 2.5.0 | getOrSet, in-memory primary | 9,470 | 99.9 | 11,003 · 72.85% |
- Warm hit: 10,000 resident keys, 500,000 awaited
getOrSetcalls in random order. Lower is better. - Cold key: 10,000 concurrent callers ask for one cold key; the loader takes 20 ms, so 20 ms is the floor. Every library called the loader once.
- Skewed traffic: Zipf α = 1.0 over 100,000 keys, room for 10% of them, 300,000 calls with an instant loader.
encodedrows decode a private copy of a ~1 KiB record on every hit. Every other library, and thereferencerows, return the stored object.
With S3-FIFO, the default since these timings were taken, the read-through hit ratio on the same traffic is 75.89%: 72,341 loader calls, against 81,442 for every other library.
In a same-session rerun on a busier machine after the optimization round of 2026-11-12, the reference-mode warm hit was level with layered-loader (234.9 against 232.4 ns), and read-through over Zipf traffic cost 1,063 ns, against 453.6 ns for layered-loader and 1,068 ns for async-cache-dedupe. Compare rows within one run, not across runs.
In-memory caches, measured
Plain in-memory caches do less, and some of them do it faster:
- Warm hit (100,000 entries): 58.2 ns for @isaacs/ttlcache, 79.2 ns for
MemoryStorein reference mode with SIEVE, 94.6 ns for lru-cache and 99.0 ns for quick-lru. - Insert into a full cache: 182 ns for quick-lru and 211 ns for lru-cache, against 570 to 593 ns for
MemoryStorein reference mode; a later side-by-side run cutMemoryStoreinserts by 34% to 35%. Every write measures the value, charges a shared memory budget, and keeps an expiry time and an eviction order. - Hit ratio on skewed traffic (Zipf α = 1.0, room for 10% of 100,000 keys): 78.23% for
MemoryStorewith S3-FIFO, 76.64% for quick-lru, which holds up to twice its configured size, and 73.59% for lru-cache. - Retained memory per entry (100,000 small values): 57.1 bytes for lru-cache, 74.5 for
MemoryStorein reference mode with LRU, 76.1 in encoded mode with LRU, 98.4 in encoded mode with S3-FIFO, 76.8 for quick-lru and 77.1 for @isaacs/ttlcache.
Features compared
Read from each library's own README at the version benchmarked, on 2026-11-12. ✓ means its README describes the feature. "—" means its README does not mention it, which is not proof that the library lacks it: check the library's full documentation before relying on a "—". Corrections are welcome, with a link, as an issue on GitHub.
| lazy-layers-cache 8.0.0 | bentocache 1.6.1 | cache-manager 7.2.9 | cacheable 2.5.0 | cachified 5.6.3 | async-cache-dedupe 3.4.0 | layered-loader 17.0.0 | |
|---|---|---|---|---|---|---|---|
| In-memory L1 in front of a shared L2 | ✓ Redis, Cloudflare KV, Durable Objects, MongoDB | ✓ Redis, Upstash, SQL, DynamoDB, file, Vercel KV | ✓ any Keyv store, several at once | ✓ primary and secondary (Keyv) | one store per call (adapters: Redis, Cloudflare KV, SQLite) | one store: memory or Redis | ✓ in-memory and Redis |
| One load per key per process, however many callers (measured: 1 loader call for 10,000 callers) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| One load per key across processes (distributed lease) | ✓ ownership-checked publish, renewal, loss detection | — | — | — | — | — | — |
| Waiters on other processes woken when that load finishes | ✓ over the event bus, polling as fallback | — | — | — | — | — | — |
| Peer L1 kept in sync over a bus | ✓ Redis, RabbitMQ, NATS Core, NATS JetStream, Durable Objects, MongoDB | ✓ Redis, RabbitMQ | — | ✓ CacheSync (pub/sub) | — | — | ✓ Redis pub/sub, SQS |
| Peers' L1 warmed with the loaded value | ✓ set broadcast, size-capped | — | — | ✓ replicates sets | — | — | — |
| Serve a stale value when the origin fails | ✓ failSafe | ✓ grace periods | — | — | — | — | — |
| Stale-while-revalidate | ✓ | ✓ soft timeouts | — | — | ✓ | ✓ stale | ✓ |
| Refresh before expiry | ✓ earlyRefresh | — | ✓ refreshThreshold | — | — | — | ✓ preemptive refresh |
| Invalidate by tag or group | ✓ tokens, no key scan, safe across clock skew | ✓ tags | — | ✓ tags | — | partial: references | ✓ groups |
| Invalidate by pattern | ✓ deleteByPattern('tenant:42:*') | — | — | — | — | — | — |
| Namespaces | ✓ nested, with clear() | ✓ | — | ✓ | — | — | Redis key prefix |
| Batch loads | ✓ getOrSetMany, one loader call | — | ✓ mget | ✓ setMany / getMany | — | — | ✓ GroupLoader, bulk fetch |
| Synchronous L1 read | ✓ peekLocal | — | — | — | — | — | ✓ |
| L1 limited by bytes, not only entries | ✓ shared budget, exact for encoded values | — | — | — | — | — | — |
| L1 gives memory back under process pressure (heap, RSS, free memory, Linux PSI) | ✓ on by default | — | — | — | — | — | — |
| Choice of eviction policy | ✓ S3-FIFO (default), LRU, SIEVE, FIFO, custom | — | — | — | — | — | — |
| Admission control (a new value must beat what it evicts) | ✓ frequency sketch, size-aware | — | — | — | — | — | — |
| Compression | ✓ LZ4, Zstandard, Snappy, gzip, chosen by size | — | — | — | — | — | — |
| Limits on hostile or corrupt payloads before decoding | ✓ | — | — | — | — | — | — |
| Circuit breakers for L2 and the bus | ✓ | — | — | — | — | — | — |
| Prometheus metrics | ✓ built in | ✓ with a Grafana dashboard | — | — | — | — | — |
| Live dashboard | ✓ built in, token-protected | — | — | — | — | — | — |
| Cloudflare Workers | ✓ Worker-safe entry, KV store, Durable Object coordination | — | — | — | ✓ KV adapter | — | — |
| Locks, counters and rate limits without Redis | ✓ Durable Objects or MongoDB | — | — | — | — | — | — |
lazy-layers-cache vs bentocache
Both READMEs describe an in-memory L1 in front of a shared L2, one load per key per process, a bus that keeps peers' L1 in sync, serving a stale value when the origin fails (failSafe in lazy-layers-cache, grace periods in bentocache), stale-while-revalidate, tags, namespaces and Prometheus metrics.
The lazy-layers-cache README also describes one load per key across processes with a distributed lease, waking the waiting servers when that load finishes, warming peers' L1 with the loaded value, refresh before expiry, pattern invalidation, batch loads, a synchronous L1 read, an L1 limited by bytes that gives memory back under process pressure, a choice of eviction policy, compression, circuit breakers, a live dashboard, and Cloudflare Workers. bentocache's README describes more L2 drivers (Upstash, SQL, DynamoDB, file and Vercel KV) and a Grafana dashboard for its metrics.
Measured in-process: a warm hit costs 180 ns in reference mode (1,504 ns encoded) against 1,120 ns for bentocache with serialize: false (2,429 ns by default), and 10,000 callers on one cold key all had the value in 30.2 ms against 89.8 ms. On skewed traffic with misses, bentocache with serialize: false was slightly faster per call, 1,936 against 2,011 ns, while lazy-layers-cache hit more keys.
lazy-layers-cache vs cache-manager and cacheable
cache-manager wraps any Keyv store, several at once, and its README describes refresh before expiry (refreshThreshold) and batch reads (mget). cacheable has a primary and a secondary Keyv store, keeps peers in sync with CacheSync over pub/sub and replicates sets, and describes tags, namespaces and setMany / getMany. Neither README describes a cross-process load lease or a byte-limited L1. Measured, a warm hit costs 9,337 ns in cache-manager and 9,470 ns in cacheable, against 180 ns in lazy-layers-cache in reference mode.
lazy-layers-cache vs layered-loader and async-cache-dedupe
These two have the lowest overhead on a single process. On skewed traffic, a read-through call cost 435 ns in layered-loader and 911 ns in async-cache-dedupe, against 2,011 ns in lazy-layers-cache in reference mode, and async-cache-dedupe served the 10,000-caller herd fastest, in 25.1 ms. A lazy-layers-cache miss also arms a timeout, takes an origin slot, keeps a fail-safe snapshot of what it evicts and accounts for its memory; that bookkeeping pays off with several processes. layered-loader's README describes keeping peers in sync over Redis pub/sub or SQS, preemptive refresh, groups and bulk loads; async-cache-dedupe's describes a memory or Redis store and stale values.
Where another library is the better choice
- Smallest, fastest plain LRU map:
lru-cache,quick-lruor@isaacs/ttlcache. They insert faster, hold less per entry, and do nothing else. Use them when you need a boundedMapand nothing more. - Most storage drivers: bentocache ships SQL, DynamoDB, file and Upstash drivers. Lazy Layers ships Redis, Cloudflare KV, Durable Objects and MongoDB, and a conformance kit to add others.
- Lowest-overhead read-through on a single process: layered-loader and async-cache-dedupe are a few hundred nanoseconds per call on misses, where Lazy Layers spends more on bookkeeping that only pays off with several processes.
Not measured yet
- Redis over a real network: round trips are counted, not timed, and the lock-wait numbers use an in-memory Redis double.
- Many instances under load at once, and rolling deploys under traffic.
- Production traces; every trace is synthetic.
- Throughput under many concurrent connections.
If a number does not reproduce, open a benchmark dispute.
Questions
Is lazy-layers-cache faster than bentocache?
In the in-process read-through benchmark in BENCHMARKS.md, yes on a warm hit and under a herd: 180 ns per hit in reference mode (1,504 ns encoded) against 1,120 ns for bentocache with serialize: false (2,429 ns by default), and 30.2 ms against 89.8 ms for 10,000 callers on one cold key. On skewed traffic with misses, bentocache with serialize: false was slightly faster per call, 1,936 against 2,011 ns, while lazy-layers-cache hit more keys.
What does lazy-layers-cache describe that bentocache's README does not?
One load per key across processes with a Redis lease, waking waiting servers when that load finishes, warming peers' L1 with the loaded value, pattern invalidation, batch loads, an L1 limited by bytes that shrinks under memory pressure, a choice of eviction policy, and Cloudflare Workers support. A missing entry in a README is not proof a library lacks the feature. bentocache's README describes more storage drivers: SQL, DynamoDB, file, Upstash and Vercel KV.
Should I use lru-cache or lazy-layers-cache?
Use lru-cache, quick-lru or @isaacs/ttlcache when you need a bounded in-memory map and nothing more: they insert faster and hold less per entry. Use lazy-layers-cache when you need read-through loading, stampede protection, a shared L2 or invalidation across instances.
Which read-through cache has the lowest overhead on one process?
layered-loader and async-cache-dedupe: 435 and 911 ns per call on skewed traffic in BENCHMARKS.md, against 2,011 ns for lazy-layers-cache in reference mode, which spends more on bookkeeping that pays off with several processes.