TypeScript API / laikacms/storage / MemoryCache
Class: MemoryCache<K, V>
Simple in-memory implementation of AsyncCache Useful for testing or simple use cases
Type Parameters
| Type Parameter |
|---|
K |
V |
Implements
AsyncCache<K,V>
Constructors
Constructor
new MemoryCache<K, V>(): MemoryCache<K, V>;Returns
MemoryCache<K, V>
Methods
clear()
clear(): Promise<void>;Clear all entries from the cache
Returns
Promise<void>
Implementation of
delete()
delete(key): Promise<boolean>;Delete a key from the cache
Parameters
| Parameter | Type |
|---|---|
key | K |
Returns
Promise<boolean>
true if the key existed and was deleted, false otherwise
Implementation of
entries()
entries(): Promise<[K, V][]>;Get all entries in the cache (excluding expired ones)
Returns
Promise<[K, V][]>
Implementation of
forEach()
forEach(callback): Promise<void>;Iterate over all entries in the cache (excluding expired ones)
Parameters
| Parameter | Type |
|---|---|
callback | (value, key) => void | Promise<void> |
Returns
Promise<void>
Implementation of
get()
get(key): Promise<V | undefined>;Get a value from the cache Returns undefined if the key doesn't exist or has expired
Parameters
| Parameter | Type |
|---|---|
key | K |
Returns
Promise<V | undefined>
Implementation of
has()
has(key): Promise<boolean>;Check if a key exists in the cache and has not expired
Parameters
| Parameter | Type |
|---|---|
key | K |
Returns
Promise<boolean>
Implementation of
keys()
keys(): Promise<K[]>;Get all keys in the cache (excluding expired ones)
Returns
Promise<K[]>
Implementation of
set()
set(
key,
value,
expiresAt?
): Promise<void>;Set a value in the cache with optional expiration
Parameters
| Parameter | Type | Description |
|---|---|---|
key | K | The cache key |
value | V | The value to cache |
expiresAt? | Date | Optional expiration date. If not provided, the entry never expires |
Returns
Promise<void>
Implementation of
size()
size(): Promise<number>;Get the number of entries in the cache (including expired ones) Note: Some implementations may exclude expired entries
Returns
Promise<number>
Implementation of
values()
values(): Promise<V[]>;Get all values in the cache (excluding expired ones)
Returns
Promise<V[]>