Class MemoryCacheAdapter<TType>

The MemoryCacheAdapter is used for easily fakingICache for testing.

IMPORT_PATH: "@daiso-tech/core/cache/memory-cache-adapter"

Type Parameters

  • TType = unknown

Implements

Constructors

Methods

  • The getOrAdd method retrieves the value for the given key if it exists, otherwise adds the valueToAdd to the cache and returns it.

    Parameters

    • key: string

      The cache key to retrieve or add.

    • valueToAdd: TType

      The value to store if the key is not found.

    • ttl: null | TimeSpan

      Optional time-to-live for the cached item. If null is passed, the item will not expire.

    • context: IReadableContext

      Readable execution context for the operation

    Returns Promise<TType>

    The cached value if the key exists, or the newly added value.

  • Increments a numeric cache entry by a given amount. Useful for counters, rates, and statistics.

    Parameters

    • key: string

      Cache key to increment

    • value: number

      Amount to increment by.

    • _context: IReadableContext

    Returns Promise<boolean>

    true if the entry was incremented, false if the key did not exist

    If the cached value is not a number