Skip to main content
Version: Next

CacheProvider

CacheProvider

Abstract class for cache providers. This class defines the methods that any cache provider must implement.

Signature
class 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).