MemoryCache
@blobs/sdk / cache / MemoryCache
Defined in: cache/MemoryCache.ts:12
In-process cache provider backed by a Map.
Used as the default CacheProvider in non-browser environments (Node, workers) and as a fallback when localStorage is unavailable. The provider runs an internal cleanup interval every five minutes to evict expired entries; call MemoryCache.destroy to stop the interval and release the cache when the SDK is being torn down.
Implements
Constructors
Constructor
new MemoryCache(
options?):MemoryCache
Defined in: cache/MemoryCache.ts:21
Parameters
options?
CacheOptions = {}
Provider configuration (CacheOptions).
Returns
MemoryCache
Methods
get()
get<
T>(key):Promise<T|null>
Defined in: cache/MemoryCache.ts:49
Reads a value, evicting and returning null if it has expired.
Type Parameters
T
T = any
Expected value type.
Parameters
key
string
The cache key to read.
Returns
Promise<T | null>
Implementation of
set()
set<
T>(key,value,ttl?):Promise<void>
Defined in: cache/MemoryCache.ts:75
Writes a value, recording the current timestamp for TTL tracking.
Type Parameters
T
T = any
Value type being stored.
Parameters
key
string
The cache key to write.
value
T
The value to store.
ttl?
number
Optional TTL in milliseconds; falls back to CacheOptions.defaultTTL.
Returns
Promise<void>
Implementation of
remove()
remove(
key):Promise<void>
Defined in: cache/MemoryCache.ts:91
Removes a single entry.
Parameters
key
string
The cache key to remove.
Returns
Promise<void>
Implementation of
clear()
clear():
Promise<void>
Defined in: cache/MemoryCache.ts:99
Removes every entry from the cache.
Returns
Promise<void>
Implementation of
has()
has(
key):Promise<boolean>
Defined in: cache/MemoryCache.ts:109
Reports whether a non-expired entry exists; evicts on the fly if expired.
Parameters
key
string
The cache key to probe.
Returns
Promise<boolean>
Implementation of
keys()
keys(
pattern?):Promise<string[]>
Defined in: cache/MemoryCache.ts:124
Lists keys, optionally filtered by substring match.
Parameters
pattern?
string
Optional substring; only matching keys are returned.
Returns
Promise<string[]>
Implementation of
clearExpired()
clearExpired():
Promise<void>
Defined in: cache/MemoryCache.ts:134
Sweeps the map and removes any entries whose TTL has elapsed. Invoked automatically by the internal cleanup timer.
Returns
Promise<void>
destroy()
destroy():
void
Defined in: cache/MemoryCache.ts:151
Stops the cleanup timer and clears the cache. Call when shutting down the SDK to avoid leaking the interval.
Returns
void