Type Alias IReadableCache<TType>

IReadableCache: {
    exists(key: string): Promise<boolean>;
    get(key: string): Promise<null | TType>;
    getOr(
        key: string,
        defaultValue: AsyncLazyable<NoneFunc<TType>>,
    ): Promise<TType>;
    getOrFail(key: string): Promise<TType>;
    missing(key: string): Promise<boolean>;
}

The IReadableCache contract defines a read-only interface for accessing cached key-value pairs. It provides methods to retrieve values independent of the underlying cache storage backend (Redis, Memcached, database, etc.). Use this contract when you need read-only access to cache data without mutation capabilities.

IMPORT_PATH: "@daiso-tech/core/cache/contracts"

Type Parameters

  • TType = unknown

Type declaration

  • exists:function
    • Checks if a key exists in the cache.

      Parameters

      • key: string

        The cache key to check

      Returns Promise<boolean>

      true if the key exists, false otherwise

  • get:function
    • Retrieves a cached value by key.

      Parameters

      • key: string

        The cache key to retrieve

      Returns Promise<null | TType>

      The cached value, or null if the key is not found or has expired

  • getOr:function
  • getOrFail:function
    • Retrieves a cached value by key, throwing an error if not found.

      Parameters

      • key: string

        The cache key to retrieve

      Returns Promise<TType>

      The cached value

      If the key is not found or has expired

  • missing:function
    • Checks if a key does not exist in the cache.

      Parameters

      • key: string

        The cache key to check

      Returns Promise<boolean>

      true if the key is missing, false if it exists