Core cache interface that all cache implementations must conform to. Provides async operations for getting, setting, and managing cached data.

const cache: ICache<string> = new MemoryCache();
await cache.set('key', 'value');
const value = await cache.get('key'); // 'value'
interface ICache<T> {
    config: common.apis.cache.CacheConfig;
    clear(): Promise<void>;
    delete(key: string): Promise<boolean>;
    get(key: string): Promise<null | T>;
    has(key: string): Promise<boolean>;
    keys(): Promise<string[]>;
    set(key: string, value: T, options?: common.apis.cache.CacheSetOptions): Promise<void>;
    size(): Promise<number>;
}

Type Parameters

  • T = any

    The type of values stored in the cache

Implemented by

Properties

Methods

Properties

Cache configuration

Methods

  • Removes a specific key from the cache.

    Parameters

    • key: string

      The cache key to delete

    Returns Promise<boolean>

    True if the key was successfully deleted

  • Retrieves a value from the cache by key.

    Parameters

    • key: string

      The cache key to retrieve

    Returns Promise<null | T>

    The cached value or null if not found or expired

  • Checks if a key exists in the cache and is not expired.

    Parameters

    • key: string

      The cache key to check

    Returns Promise<boolean>

    True if the key exists and is valid