interface CacheMiddlewareOptions
Since 0.1.0

Options for the transparent response-caching middleware.

Examples

Example 1

import { cacheMiddleware } from '@setu-ts/cache-plugin';

app.router.use('/api/data', cacheMiddleware({ ttlSeconds: 300 }));

Properties

optional
ttlSeconds: number

Per-route TTL override in seconds.

optional
key: (ctx: IRequestContext) => string

Custom cache key generator. Defaults to ${request.method}:${request.url}.

The tenant discriminator segment is composed around this key too, so a tenant-aware application stores one entry per tenant regardless.

optional
vary: (ctx: IRequestContext) => readonly string[]

Per-request discriminator values appended to the cache key after the tenant segment. Each returned string is length-prefixed and joined in order, so two requests differing in any value never share an entry. Omitted leaves the key unchanged.

optional
bypass: (ctx: IRequestContext) => boolean

Bypass function — when true, skip caching entirely for this request and pass through to the handler.

optional
store: string

Capability token for the cache store to use. Defaults to CAPABILITIES.CACHE.

optional
cacheableStatuses: number[]

HTTP status codes eligible for caching. Defaults to [200].

Usage

import { type CacheMiddlewareOptions } from "cache-plugin/src/index.ts";