web / lib/services/cache/storage/memory
lib/services/cache/storage/memory
In-memory cache storage implementation using LRU cache.
This storage backend keeps all cache entries in memory using an LRU (Least Recently Used) eviction policy. It’s fast and efficient for development and testing, but data is lost when the process restarts.
Classes
MemoryCacheStorage
Cache storage interface for different backends
Implements
Constructors
Constructor
new MemoryCacheStorage(
options):MemoryCacheStorage
Parameters
options
MemoryCacheOptions = {}
Returns
Methods
get()
get<
T>(key):Promise<null|CacheEntry<T>>
Get a value from cache
Type Parameters
T
T
Parameters
key
string
Returns
Promise<null | CacheEntry<T>>
Implementation of
set()
set<
T>(key,value,options?):Promise<void>
Set a value in cache
Type Parameters
T
T
Parameters
key
string
value
T
options?
Returns
Promise<void>
Implementation of
delete()
delete(
key):Promise<boolean>
Delete a value from cache
Parameters
key
string
Returns
Promise<boolean>
Implementation of
has()
has(
key):Promise<boolean>
Check if key exists
Parameters
key
string
Returns
Promise<boolean>
Implementation of
clear()
clear(
pattern?):Promise<number>
Clear cache entries matching pattern
Parameters
pattern?
string
Returns
Promise<number>
Number of entries cleared
Implementation of
keys()
keys(
pattern?):Promise<string[]>
Get all keys matching pattern
Parameters
pattern?
string
Returns
Promise<string[]>
Implementation of
getMany()
getMany<
T>(keys):Promise<Map<string,CacheEntry<T>>>
Get multiple values at once
Type Parameters
T
T
Parameters
keys
string[]
Returns
Promise<Map<string, CacheEntry<T>>>
Implementation of
setMany()
setMany<
T>(entries,options?):Promise<void>
Set multiple values at once
Type Parameters
T
T
Parameters
entries
Map<string, T>
options?
Returns
Promise<void>
Implementation of
getStats()
getStats():
Promise<CacheStats>
Get cache statistics
Returns
Promise<CacheStats>
Implementation of
cleanup()
cleanup():
Promise<number>
Clean up expired entries
Returns
Promise<number>
Number of entries cleaned
Implementation of
destroy()
destroy():
void
Destroy the storage (cleanup resources)
Returns
void