Documentation
Welcome to the Layercache documentation.
Layercache stacks memory, Redis, and disk behind a single API with stampede prevention, tag invalidation, stale-while-revalidate, and full observability.
How It Works
Every read follows the same path:
- Check L1 Memory first (fastest, in-process).
- If miss, check L2 Redis (shared across instances).
- If miss, check L3 Disk (persistent fallback).
- If all miss, run the origin fetcher once (single-flight).
- Backfill upper layers so next reads return faster.
Layercache keeps responses stable under pressure with stale serving, circuit breakers, and timeout guards.
Version 4.0 Highlights
Layercache 4.0 makes missing values unambiguous and hardens production coordination boundaries:
- Public cache reads return
undefinedon misses while preserving intentional cachednullvalues. - Read-through fetchers cache
nullby default;cacheNullValues: falseretains legacy null-as-absence behavior. - Structured
wrap()keys use the collision-resistantj2:schema, and write ordering plus generation cleanup have finite limits. - Snapshot commits, signed invalidation, HTTP credential handling, destructive CLI patterns, and playground isolation are hardened.
- Regression coverage includes the merged scheduler, snapshot, invalidation, and epoch rollover fixes.
Read the migration guide before upgrading an existing deployment.
Quick Links
- Getting Started — Install and configure your first cache stack
- Tutorial — 10-step walkthrough of production features
- API Reference — Complete method and option documentation
- Integrations — Express, Fastify, NestJS, Hono, tRPC, GraphQL