Methods

  • Clears all data from the cache.

    Returns Promise<boolean>

    Whether the cache was cleared

  • Clears all entries that match the given prefix

    Parameters

    • prefix: string

      The prefix to use for filtering keys

    Returns Promise<void>

  • Deletes data from the cache, by it's key.

    Parameters

    • key: string

      The key to delete the data for

    Returns Promise<boolean>

    Whether the key existed in the cache

  • Enforces a maximum size for a set/category of keys by deleting the oldest keys if the size exceeds the maximum. The keys should be tracked by using prefixes (e.g. 'categoryName:categoryKey')

    Parameters

    • prefix: string

      The prefix to use for filtering keys

    • maxSize: number

      The maximum size to enforce

    Returns Promise<void>

    Promise

  • Retrieves data from the cache, by it's key.

    Type Parameters

    • T

    Parameters

    • key: string

      The key to retrieve the data for

    Returns Promise<null | T>

    The data for the key, or null if it doesn't exist

  • Checks if a key exists in the cache.

    Parameters

    • key: string

      The key to check for

    Returns Promise<boolean>

    Whether the key exists in the cache

  • Sets/categories should be tracked by using prefixes (e.g. 'categoryName:categoryKey') This method returns all keys that match the given prefix.

    Parameters

    • prefix: string

    Returns Promise<string[]>

  • Sets data in the cache, by it's key.

    Type Parameters

    • T

    Parameters

    • key: string
    • value: T
    • ttl: number

    Returns Promise<void>

  • Hashes a key using SHA-256.

    Parameters

    • key: string

      The key to hash

    Returns string

    The hashed key

  • Hashes an object using SHA-256, uses JSON.stringify to convert the object to a string.

    Parameters

    • obj: unknown

      The object to hash

    Returns string

    The hashed key for the object