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:

  1. Check L1 Memory first (fastest, in-process).
  2. If miss, check L2 Redis (shared across instances).
  3. If miss, check L3 Disk (persistent fallback).
  4. If all miss, run the origin fetcher once (single-flight).
  5. 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 undefined on misses while preserving intentional cached null values.
  • Read-through fetchers cache null by default; cacheNullValues: false retains legacy null-as-absence behavior.
  • Structured wrap() keys use the collision-resistant j2: 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.

  • 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