CacheOptions
Interface: CacheOptions
Defined in: packages/cache/src/cache.ts:19
Options controlling cache key generation and storage behavior.
Properties
cacheMap?
optionalcacheMap?: (options) =>CacheMap
Defined in: packages/cache/src/cache.ts:82
Custom CacheMap implementation constructor.
Parameters
options
CacheOptions
Returns
cacheStorage?
optionalcacheStorage?: (options?) =>CacheStorage
Defined in: packages/cache/src/cache.ts:86
Custom CacheStorage implementation constructor.
Parameters
options?
CacheOptions
Returns
classKeyGenerator?
optionalclassKeyGenerator?: (instance) =>any
Defined in: packages/cache/src/cache.ts:32
Generator for the instance-level cache key (e.g., per this).
Parameters
instance
object
Returns
any
enableStats?
optionalenableStats?:boolean
Defined in: packages/cache/src/cache.ts:50
Enable cache statistics tracking (hits, misses, evictions).
gcInterval?
optionalgcInterval?:number
Defined in: packages/cache/src/cache.ts:46
Automatic garbage collection interval (in milliseconds). When set, expired entries are automatically cleaned up.
hashStrategy?
optionalhashStrategy?:"sha256"|"simple"
Defined in: packages/cache/src/cache.ts:78
Algorithm to use for default argument key generation.
'sha256'(default): Hashes the serialized arguments with SHA-256. Collision-resistant and produces fixed-length keys, but involves a crypto operation on every cache miss.'simple': Uses a typed, length-prefixed string encoding without hashing. Faster for hot paths but produces longer keys proportional to argument size.
Has no effect when a custom methodKeyGenerator is provided.
maxSize?
optionalmaxSize?:number
Defined in: packages/cache/src/cache.ts:41
Maximum number of entries per instance cache. When exceeded, least recently used entries are evicted.
methodKeyGenerator?
optionalmethodKeyGenerator?: (property,args) =>string|undefined
Defined in: packages/cache/src/cache.ts:28
Define how to cache the method call. If undefined is returned then no caching is done.
Parameters
property
string
args
any[]
Returns
string | undefined
shouldCache?
optionalshouldCache?: (result) =>boolean
Defined in: packages/cache/src/cache.ts:65
Predicate to decide whether a result should be cached.
Return false to skip caching for a specific result value.
Called with the resolved value for async methods.
Parameters
result
any
Returns
boolean
Examples
// Only cache non-null results
shouldCache: (result) => result !== null
// Only cache successful HTTP responses
shouldCache: (result) => result?.status === 200
ttl?
optionalttl?:number
Defined in: packages/cache/src/cache.ts:36
Define how long the cache should be kept (in milliseconds).