CacheBackend
Import
Section titled “Import”import type { CacheBackend, CacheBackendOptions } from '@requence/cache'Interface
Section titled “Interface”interface CacheBackend { get(key: string, args: string): Promise<any> getTags(key: string, args: string): Promise<string[]> set(key: string, args: string, collectionResult: BackendCollectionResult): Promise<void> invalidateArgs(key: string, args: string): Promise<void> invalidateKey(key: string): Promise<void> invalidateTag(tag: string): Promise<void> reset(): Promise<void>}Methods
Section titled “Methods”get(key, args)
Section titled “get(key, args)”Retrieve a cached value. Should throw if the key is not found.
getTags(key, args)
Section titled “getTags(key, args)”Return the tags associated with a cached entry.
set(key, args, collectionResult)
Section titled “set(key, args, collectionResult)”Store a result. The collectionResult is a Promise that resolves to the computed value, tags, and a shouldCache flag.
invalidateArgs(key, args)
Section titled “invalidateArgs(key, args)”Remove a specific cached entry.
invalidateKey(key)
Section titled “invalidateKey(key)”Remove all entries for a given function key.
invalidateTag(tag)
Section titled “invalidateTag(tag)”Remove all entries associated with a tag.
reset()
Section titled “reset()”Clear all data from the backend.
Built-in Implementations
Section titled “Built-in Implementations”| Backend | Module | Description |
|---|---|---|
MemoryBackend | @requence/cache | In-memory Map-based storage with TTL and LRU eviction |
RedisBackend | @requence/cache/redis | Redis-backed storage with Pub/Sub coordination |
CombinedBackend | (internal) | Wraps multiple backends as a single read-through chain |