Skip to main content

CacheStorage

@webda/cache


Class: CacheStorage

Defined in: packages/cache/src/cache.ts:98

Storage for cached method results for a single instance.

Maintains an internal timestamp per entry to support TTL-based invalidation during reads and garbage collection.

Keys are method-level cache keys produced by methodKeyGenerator. Supports LRU eviction when maxSize is configured.

Extends​

  • Map<string, { timestamp: number; value: any; }>

Constructors​

Constructor​

new CacheStorage(options?): CacheStorage

Defined in: packages/cache/src/cache.ts:104

Create a new CacheStorage.

Parameters​

options?​

CacheOptions

cache configuration options

Returns​

CacheStorage

Overrides​

Map<string, { value: any; timestamp: number }>.constructor

Properties​

[toStringTag]​

readonly [toStringTag]: string

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:137

Inherited from​

CacheMap.[toStringTag]


size​

readonly size: number

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts:45

Returns​

the number of elements in the Map.

Inherited from​

CacheMap.size


stats​

stats: CacheStats

Defined in: packages/cache/src/cache.ts:99


[species]​

readonly static [species]: MapConstructor

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:319

Inherited from​

Map.[species]

Methods​

[iterator]()​

[iterator](): MapIterator<[string, { timestamp: number; value: any; }]>

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts:143

Returns an iterable of entries in the map.

Returns​

MapIterator<[string, { timestamp: number; value: any; }]>

Inherited from​

Map.[iterator]


clear()​

clear(): void

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts:20

Returns​

void

Inherited from​

Map.clear


delete()​

delete(key): boolean

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts:24

Parameters​

key​

string

Returns​

boolean

true if an element in the Map existed and has been removed, or false if the element does not exist.

Inherited from​

Map.delete


deleteCachedMethod()​

deleteCachedMethod(key): void

Defined in: packages/cache/src/cache.ts:184

Delete cache entries. If the key ends with $, all entries starting with the prefix are removed.

Parameters​

key​

string

the method cache key or prefix

Returns​

void


entries()​

entries(): MapIterator<[string, { timestamp: number; value: any; }]>

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts:148

Returns an iterable of key, value pairs for every entry in the map.

Returns​

MapIterator<[string, { timestamp: number; value: any; }]>

Inherited from​

Map.entries


forEach()​

forEach(callbackfn, thisArg?): void

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts:28

Executes a provided function once per each key/value pair in the Map, in insertion order.

Parameters​

callbackfn​

(value, key, map) => void

thisArg?​

any

Returns​

void

Inherited from​

Map.forEach


garbageCollect()​

garbageCollect(): void

Defined in: packages/cache/src/cache.ts:200

Remove all expired entries based on TTL.

Returns​

void


get()​

get(key): { timestamp: number; value: any; } | undefined

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts:33

Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.

Parameters​

key​

string

Returns​

{ timestamp: number; value: any; } | undefined

Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.

Inherited from​

Map.get


getCachedMethod()​

getCachedMethod(key): any

Defined in: packages/cache/src/cache.ts:173

Retrieve the cached value for the given method key (without TTL re-check).

Parameters​

key​

string

the method cache key

Returns​

any

the cached value or undefined


getStats()​

getStats(): CacheStats

Defined in: packages/cache/src/cache.ts:221

Get current cache statistics.

Returns​

CacheStats

a copy of the current stats


has()​

has(key): boolean

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts:37

Parameters​

key​

string

Returns​

boolean

boolean indicating whether an element with the specified key exists or not.

Inherited from​

Map.has


hasCachedMethod()​

hasCachedMethod(key): boolean

Defined in: packages/cache/src/cache.ts:115

Check whether a cached value exists and is still valid. Applies TTL: if an entry is expired, it is evicted and treated as missing.

Parameters​

key​

string

the method cache key

Returns​

boolean

true if a valid cached entry exists


keys()​

keys(): MapIterator<string>

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts:153

Returns an iterable of keys in the map

Returns​

MapIterator<string>

Inherited from​

Map.keys


resetStats()​

resetStats(): void

Defined in: packages/cache/src/cache.ts:228

Reset cache statistics to zero.

Returns​

void


set()​

set(key, value): this

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts:41

Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.

Parameters​

key​

string

value​
timestamp​

number

value​

any

Returns​

this

Inherited from​

Map.set


setCachedMethod()​

setCachedMethod(key, _args, value): void

Defined in: packages/cache/src/cache.ts:143

Store a cached value for the given method key. Implements LRU eviction when maxSize is reached.

Note: args is accepted for potential future strategies but not used here.

Parameters​

key​

string

the method cache key

_args​

any[]

original method arguments (reserved)

value​

any

the value to cache

Returns​

void


values()​

values(): MapIterator<{ timestamp: number; value: any; }>

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts:158

Returns an iterable of values in the map

Returns​

MapIterator<{ timestamp: number; value: any; }>

Inherited from​

Map.values