Skip to main content
Docs
๐Ÿ”ฅ
v2.0 โ€” Production Caching Infrastructure for Express.js

Production caching infrastructure for Express โ€” routes, services, and beyond.

Cache any Express route or async function with SWR, O(1) invalidation, and stampede protection. Redis, Memcached & in-memory adapters. TypeScript-first.

View Documentation
GitHubยทnpmยทMIT Licenseยท100% TypeScript
O(1)

Epoch Invalidation

Instant nested key updates without scanning Redis keys
99%

DB Query Reduction

Saves databases from melting under peak concurrent load
< 4ms

Avg Cache-Hit Latency

SWR serving from Redis on loopback โ€” benchmark in README
Pure TS

TypeScript-First API

Fully type-safe schemas, options, and event listeners

Explore Caching Mechanics

Click the tabs to toggle code patterns, and run the simulator to see the background orchestration logs in action.

import express from 'express';
import { createCache, createRedisAdapter } from '@express-route-cache/core';

const app = express();
const cache = createCache({
  adapter: createRedisAdapter({ host: 'localhost' }),
  staleTime: 60, // Fresh for 60s
  gcTime: 300,   // Keep stale for 5m
  swr: true      // Background revalidation
});

// Cache this route globally
app.get('/api/users/:id', cache.route(), (req, res) => {
  res.json({ id: req.params.id, name: 'Alex' });
});
Simulation Monitor
Requests sent: 0
Visual Request Stream
No requests simulated yet. Click below to run a test.
TERMINAL OUTPUT
Console logs will appear here during simulation.
Two-Tier Concurrency Lock

Deflect Cache Stampedes

When a high-traffic cache key expires, the "thundering herd" hits your database simultaneously, causing load spikes or server crashes.

Our two-tier lock coordinates requests process-wide (via memory coalescing) and cluster-wide (via Redis/Memcached SETNX). Follower requests poll the cache silently while one leader generates the data.

Stampede Simulation Console
Concurrent Requests Visualizer DB Query (1) Waiting (99) Served (100)
Simulator is idle. No requests currently executing.
Ready. Click "Simulate 100 Stampeding Requests".

Anatomy of a Versioned Key

How we compose deterministic, instant-invalidating Redis keys. Click the segments to inspect how our versioning engine works.

:::โžกSHA-256 HASH

Epoch Version counters (O(1) invalidation)

Appends version counters for the route and its ancestor path nodes. By incrementing 'v:api/users', any cached requests referencing it instantly mismatch on key lookup. This invalidates millions of sub-paths (like /api/users/123/profile) in O(1) time without scanning Redis keys.

Configured via:cache.invalidateRoute('/api/users')

How We Compare

We built express-route-cache to solve production infrastructure challenges.

Invalidation

@express-route-cacheO(1) Epoch Increment
apicacheO(N) SCAN (blocks Redis)
express-cache-controllerBrowser only, no server cache

Stampede Guard

@express-route-cacheMemory + Redis coalescing
apicacheNone โ€” DB melts
node-cache-managerNone

SWR Background Refresh

@express-route-cacheBuilt-in
apicacheNone (blocking misses)
node-cache-managerNone

Non-Route Caching

@express-route-cachecache.fetch() API
apicacheNo (middleware only)
node-cache-managerYes (manual boilerplate)

Visual Dashboard

@express-route-cacheCache Studio (standalone)
apicacheNone
node-cache-managerNone

Comparison based on publicly documented features. Full comparison โ†’

Diagnostics Suite

Cache Studio

A visual dashboard built for debugging. Monitor cache hits, trace SWR background processes, and analyze key epochs. Runs inside your Express app or as a standalone CLI targeting *any* compatible Redis cluster.