In-Memory Cache Adapter | @express-route-cache
High-performance in-memory caching for single-process Express.js applications and local development. Built into @express-route-cache/core, zero dependencies.
Memory Adapter
The Memory adapter is built into @express-route-cache/core — no extra installation needed. It is perfect for single-process applications, local development, and testing.
Setup
import { createCache, createMemoryAdapter } from "@express-route-cache/core";
// Default: entries expire after 600 seconds if no explicit TTL is set
const cache = createCache({
adapter: createMemoryAdapter(),
});
// Custom default TTL
const cache = createCache({
adapter: createMemoryAdapter(3600), // entries default to 1 hour
});Signature
createMemoryAdapter(defaultTTLSeconds?: number): CacheClient| Argument | Type | Default | Description |
|---|---|---|---|
defaultTTLSeconds | number | 600 | Maximum TTL (seconds) for entries stored without an explicit TTL. Prevents unbounded memory growth. |
Limitations
- Process Local: Cache is not shared between multiple Node.js instances (e.g., in a cluster or behind a load balancer).
- Volatile: Cache is cleared whenever the server restarts.
For multi-instance or persistent caching, use the Redis or Memcached adapter instead.
Cache Adapters Overview | @express-route-cache
Compare Memory, Redis (ioredis), and Memcached (memjs) cache adapters for Express.js. Choose the right storage backend for your production environment.
Redis Cache Adapter (ioredis) | @express-route-cache
Set up distributed Express.js route caching with Redis using ioredis. Supports URL connection, existing client reuse, and key prefixing. Recommended for production.