# FAQ (https://lazy-layers-cache.vercel.app/docs/faq)

> Short answers about lazy-layers-cache: Redis, stampedes, invalidation across instances, Cloudflare Workers, failures, eviction, memory, speed, metrics and upgrading to 8.0.



Short answers to the questions people ask most about lazy-layers-cache 8.0.0. Every number comes from [BENCHMARKS.md](https://github.com/Amon20044/LazyLayers/blob/main/BENCHMARKS.md), which says how each was measured. For a side-by-side look at other libraries, see the [comparison](/docs/comparison).


## Questions

### What is lazy-layers-cache?

An open-source L1/L2 cache for Node.js and Cloudflare Workers: an in-process L1 in front of a shared L2 (Redis, Cloudflare KV, Durable Objects or MongoDB), read through with `getOrSet`, with stampede protection inside one process and across processes, and invalidation over an event bus. It is MIT-licensed, written in TypeScript, and has one runtime dependency, `msgpackr`.

### Do I need Redis?

No. In one process, `setupCache({ namespace, redis: false })` runs an in-memory L1 only. For several instances, use Redis as L2 with Redis Pub/Sub, Cloudflare KV, or `lazy-layers-cache/coordination`, which keeps locks, counters, rate limits and invalidation in Cloudflare Durable Objects or MongoDB.

### How does it prevent cache stampedes?

Concurrent `getOrSet` callers for the same missing key share one loader call in the process, and with Redis L2 a per-key lease lets one instance load while the others wait to be woken. In BENCHMARKS.md, 10,000 concurrent callers on one cold key ran the loader once.

### How do other instances learn that a value changed?

Over an event bus: Redis Pub/Sub, RabbitMQ, NATS Core, NATS JetStream, Durable Object RPC or MongoDB change streams. `invalidate`, `invalidateByPattern` and `invalidateTags` publish a delete that every peer applies to its own L1, and a freshly loaded value can be broadcast so peers do not query the database for it. `setupCache` caps that broadcast at 32 KiB.

### Does it work on Cloudflare Workers?

Yes. `lazy-layers-cache/cloudflare` is a Worker-safe entry point with a Cloudflare KV store, and `lazy-layers-cache/coordination` adds Durable Object locks, counters, rate limits, a shared cache tier and invalidation between Worker instances.

### What happens when Redis or the event bus fails?

The cache fails open: an L2 error becomes a miss and the loader runs, circuit breakers stop repeated calls to the failing dependency, and fail-safe serves a recent value when the loader fails. With managed Redis Pub/Sub, a subscription gap makes local copies untrusted, so the cache bypasses L1 until recovery restores trust.

### Which eviction policy does it use?

S3-FIFO by default, with LRU, SIEVE, FIFO and custom policies available. On the synthetic traces in BENCHMARKS.md it had the lowest mean miss ratio of the built-in policies, and on Zipf α = 1.0 traffic the in-memory store hit 78.23% with it, against 73.59% for lru-cache.

### How much memory does it use?

L1 is limited by `maxEntries` (1,000 by default) and by `maxMemory`, a byte budget shared by every built-in store in the process: 20% of effective memory by default, never more than 75%. It gives memory back when the V8 heap passes 85% of its limit or RSS passes 90% of `maxProcessMemory`, which defaults to the container or host memory. A small encoded entry retained 76.1 bytes with LRU and 98.4 with S3-FIFO in BENCHMARKS.md.

### How fast is it?

In BENCHMARKS.md a warm read-through hit costs 180 ns in reference mode and 1,610 ns in encoded mode, the default, against 6,490 ns in 0.7.0, and a miss costs 2 Redis round trips. Inserting into a full in-memory cache is slower than in lru-cache or quick-lru, because every write measures the value and charges a memory budget.

### Which Node.js versions and module formats are supported?

Node.js 20 or 22+; use 22+ with NATS, because its current transitive dependency declares that minimum. The package ships ESM, CommonJS and TypeScript declarations.

### Does it expose metrics?

Yes. With the `observability` option it serves Prometheus metrics under the `lazycache` prefix and a live dashboard protected by a generated token. Every cache operation is also an event you can subscribe to with `cache.on()`.

### How do I upgrade from 0.7 to 8.0?

Wire formats are unchanged, so 0.7 and 8.0 instances can share Redis and an event bus during a rolling deploy. Install the integrations you use (`ioredis`, `amqplib`, the NATS packages, `lz4-napi` and `snappy`), which are now optional peer dependencies, configure dashboard credentials if you relied on the old defaults, and read MIGRATION.md for the rest.