Skip to main content
Version: Next

MemoryCache

MemoryCache

MemoryCache is an in-memory cache provider that implements the CacheProvider interface. It stores cache entries in a Map and supports basic operations like get, set, exists, delete, clear, and expire.

Signature
class MemoryCache extends CacheProvider {
get(key: string) => Promise<CacheEntry<T> | undefined>;
set(key: string, value: T, ttl?: number) => Promise<void>;
exists(key: string) => Promise<boolean>;
delete(key: string) => Promise<void>;
clear() => Promise<void>;
expire(key: string, ttl: number) => Promise<void>;
}

get

method
(key: string) => Promise<CacheEntry<T> | undefined>

Retrieves a value from the cache by its key.

set

method
(key: string, value: T, ttl?: number) => Promise<void>

Sets a value in the cache with an optional time-to-live (TTL).

exists

method
(key: string) => Promise<boolean>

Checks if a cache entry exists by its key.

delete

method
(key: string) => Promise<void>

Deletes a cache entry by its key.

clear

method
() => Promise<void>

Clears all entries in the cache.

expire

method
(key: string, ttl: number) => Promise<void>

Expires a cache entry by its key after a specified time-to-live (TTL).