Service layer that delegates to a backend CacheStore while applying:
-
clear(): Promise<void>
Delegates to the backend's
clear(), which uses the construction-time prefix to scope the deletion. CacheService does not prepend a key here sinceclear()takes no key argument. -
delete(key: string): Promise<boolean>
Removes a cached value.
-
get<T>(key: string): Promise<T | null>
Reads a cached value.
-
getOrSet<T>(): Promise<T>key: string,factory: () => Promise<T>,ttlSeconds?: number
Reads a cached value or produces and stores it once for all concurrent callers of this service and key.
-
has(key: string): Promise<boolean>
Reports whether a live entry exists.
-
set<T>(): Promise<void>key: string,value: T,ttlSeconds?: number
Stores a value.
In-memory cache implementation with LRU eviction and lazy TTL expiry.
-
clear(): Promise<void>
Remove all entries scoped to this backend's prefix.
-
connect(): Promise<void>
Establish the backend connection (if applicable).
-
delete(key: string): Promise<boolean>
Delete a value. The key is already-prefixed by CacheService.
-
disconnect(): Promise<void>
Gracefully disconnect.
-
get<T>(key: string): Promise<T | null>
Read a value. The key is already-prefixed by CacheService.
-
has(key: string): Promise<boolean>
Check existence. The key is already-prefixed by CacheService.
-
isHealthy(): Promise<boolean>
Lifecycle truth (M90b): an in-process Map has no separate backend to reach, so reachability IS readiness — the process either holds the map or it does not.
-
isReady(): boolean
Reports whether the backend is ready for operations.
-
set<T>(): Promise<void>key: string,value: T,ttlSeconds?: number
Write a value. The key is already-prefixed by CacheService.
No-op implementation of CacheStore. Every method resolves without side
effects: reads return null/false, writes resolve void, and lifecycle
methods are no-ops.
-
clear(): Promise<void>
Remove all entries scoped to this backend's prefix.
-
connect(): Promise<void>
Establish the backend connection (if applicable).
-
delete(_key: string): Promise<boolean>
Delete a value. The key is already-prefixed by CacheService.
-
disconnect(): Promise<void>
Gracefully disconnect.
-
get<T>(_key: string): Promise<T | null>
Read a value. The key is already-prefixed by CacheService.
-
has(_key: string): Promise<boolean>
Check existence. The key is already-prefixed by CacheService.
-
isHealthy(): Promise<boolean>
Lifecycle truth (M90b): the no-op backend stores nothing, so the only honest reachability answer is whether the store is connected.
-
isReady(): boolean
Reports whether the backend is ready for operations.
-
set<T>(): Promise<void>_key: string,_value: T,_ttlSeconds?: number
Write a value. The key is already-prefixed by CacheService.
Redis-backed cache store implementation.
-
clear(): Promise<void>
Remove all entries scoped to this backend's prefix.
-
connect(): Promise<void>
Establish the backend connection (if applicable).
-
delete(key: string): Promise<boolean>
Delete a value. The key is already-prefixed by CacheService.
-
disconnect(): Promise<void>
Gracefully disconnect.
-
get<T>(key: string): Promise<T | null>
Read a value. The key is already-prefixed by CacheService.
-
has(key: string): Promise<boolean>
Check existence. The key is already-prefixed by CacheService.
-
isHealthy(): Promise<boolean>
Probes Redis with a typed
ping()(M90b).falseafter disconnect — a store with no client cannot answer — and otherwisetrueonly when the server answers, a rejection being unreachability. -
isReady(): boolean
Reports whether the backend is ready for operations.
-
set<T>(): Promise<void>key: string,value: T,ttlSeconds?: number
Write a value. The key is already-prefixed by CacheService.
Create a caching middleware function.
Creates the CachePlugin.
Serializable cached response payload stored in the cache backend. Body is base64-encoded when binary so that JSON-safe stores (Redis) can persist it without corruption.
-
body: string | null
Body content (decoded string or base64-encoded bytes).
-
bodyEncoding: "base64"
Present when the body was base64-encoded during storage. The replay helper decodes it back to
Uint8Array. -
headers: Array<[string, string]>
Headers as
[name, value]pairs. -
status: number
HTTP status code.
Options for the transparent response-caching middleware.
-
bypass: (ctx: IRequestContext) => boolean
Bypass function — when
true, skip caching entirely for this request and pass through to the handler. -
cacheableStatuses: number[]
HTTP status codes eligible for caching. Defaults to
[200]. -
key: (ctx: IRequestContext) => string
Custom cache key generator. Defaults to
${request.method}:${request.url}. -
store: string
Capability token for the cache store to use. Defaults to
CAPABILITIES.CACHE. -
ttlSeconds: number
Per-route TTL override in seconds.
-
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.
Options for the CachePlugin factory.
-
name: string
Plugin instance name for multi-cache setups. Derives the capability token as
cache.<name>when not'default'. -
options: CacheStoreOptions
Store-specific options.
-
store: CacheStoreType
Store backend type. Defaults to
'memory'.
Options for creating a cache store backend.
-
client: IRedisClient
Injected ioredis-compatible client (bypasses lazy import).
-
defaultTtl: number
Default TTL in seconds when
setomits ttlSeconds. -
maxSize: number
Maximum entry count for MemoryStore LRU eviction.
-
prefix: string
Key prefix applied to all cache keys.
-
url: string
Redis connection URL (used when store is
'redis').
Key/value cache with per-entry TTL.
-
clear(): Promise<void>
Removes every entry (respecting the store's key prefix, if configured).
-
delete(key: string): Promise<boolean>
Removes a cached value.
-
get<T>(key: string): Promise<T | null>
Reads a cached value.
-
has(key: string): Promise<boolean>
Reports whether a live entry exists.
-
set<T>(): Promise<void>key: string,value: T,ttlSeconds?: number
Stores a value.
Structural shape of an ioredis-compatible client. Used for validation and injection so that the plugin does not hard-depend on ioredis.
-
connect(): Promise<void>
Establish the connection.
-
del(...keys: string[]): Promise<number>
Delete one or more keys. Returns the count of removed keys.
-
exists(key: string): Promise<number>
Check if a key exists. Returns
1or0. -
get(key: string): Promise<string | null>
Get a string value by key. Returns
nullwhen missing. -
ping(): Promise<string>
Pings the server (M90b). The Redis store's reachability probe invokes it; a
PONGresponse proves the backend is reachable, and a rejection does not. The real ioredis client implements it. -
quit(): Promise<void>
Gracefully close the connection.
-
scan(): Promise<[string, string[]]>cursor: string,matcher: string,matchValue?: string
Cursor-based scan. Returns
[cursor, keys[]]. Use'0'to start and continue until cursor returns'0'. -
set(): Promise<string | null>key: string,value: string,ttlMode?: "EX",ttlSeconds?: number
Set a key with optional TTL.
Supported cache store backends.
Usage
import * as Caching_plugin_with_Memory_and_Redis_stores_and_cache_middleware___Exports_the_plugin_factory__service__store_implementations__middleware__and_all_public_option_types_ from "cache-plugin/src/index.ts";