Type Alias ICacheBase<TType>

ICacheBase: IReadableCache<TType> & {
    add(
        key: string,
        value: TType,
        settings?: CacheWriteSettings,
    ): Promise<boolean>;
    addOrFail(
        key: string,
        value: TType,
        settings?: CacheWriteSettings,
    ): Promise<void>;
    clear(): Promise<void>;
    decrement(key: string, value?: Extract<TType, number>): Promise<boolean>;
    decrementOrFail(key: string, value?: Extract<TType, number>): Promise<void>;
    getAndRemove(key: string): Promise<null | TType>;
    getOrAdd(
        key: string,
        valueToAdd: AsyncLazyable<NoneFunc<TType>>,
        settings?: GetOrAddSettings,
    ): Promise<TType>;
    increment(key: string, value?: Extract<TType, number>): Promise<boolean>;
    incrementOrFail(key: string, value?: Extract<TType, number>): Promise<void>;
    put(
        key: string,
        value: TType,
        settings?: CacheWriteSettings,
    ): Promise<boolean>;
    remove(key: string): Promise<boolean>;
    removeMany(keys: Iterable<string, any, any>): Promise<boolean>;
    removeOrFail(key: string): Promise<void>;
    update(key: string, value: TType): Promise<boolean>;
    updateOrFail(key: string, value: TType): Promise<void>;
}

The ICacheBase contract defines a way for storing and reading as key-value pairs independent of data storage.

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

Type Parameters

  • TType = unknown

Type declaration

  • add:function
    • The add method adds a key with given value when key doesn't exists.

      Parameters

      • key: string
      • value: TType
      • Optionalsettings: CacheWriteSettings
        • Optionaljitter?: number

          Random jitter factor (0-1) to add variance to expiration times. Prevents thundering herd problems when many entries expire simultaneously. A value of 0.1 adds ±10% randomness to the TTL.

        • Optionalttl?: ITimeSpan | null

          Time-to-live (TTL) duration for cached entries. When set, entries will automatically expire after this duration. Pass null to cache entries without automatic expiration.

      Returns Promise<boolean>

      Returns true when key doesn't exists otherwise false will be returned.

  • addOrFail:function
  • clear:function
    • The clear method removes all the keys in the cache. If a cache is in a group then only the keys part of the group will be removed.

      Returns Promise<void>

  • decrement:function
    • The decrement method decrements the given key with given value. An error will thrown if the value is not a number.

      Parameters

      • key: string
      • Optionalvalue: Extract<TType, number>

        If not defined then it will be defaulted to 1.

      Returns Promise<boolean>

      Returns true if the key where decremented otherwise false will be returned.

  • decrementOrFail:function
    • The decrementOrFail method decrements the given key with given value. An error will thrown if the value is not a number or if the key is not found.

      Parameters

      • key: string
      • Optionalvalue: Extract<TType, number>

        If not defined then it will be defaulted to 1.

      Returns Promise<void>

  • getAndRemove:function
    • The getAndRemove method returns the value when key is found otherwise null will be returned. The key will be removed after it is returned.

      Parameters

      • key: string

      Returns Promise<null | TType>

  • getOrAdd:function
  • increment:function
    • The increment method increments the given key with given value. An error will thrown if the value is not a number.

      Parameters

      • key: string
      • Optionalvalue: Extract<TType, number>

        If not defined then it will be defaulted to 1.

      Returns Promise<boolean>

      Returns true if the key where incremented otherwise false will be returned.

  • incrementOrFail:function
    • The incrementOrFail method increments the given key with given value. An error will thrown if the value is not a number or if the key is not found.

      Parameters

      • key: string
      • Optionalvalue: Extract<TType, number>

        If not defined then it will be defaulted to 1.

      Returns Promise<void>

  • put:function
    • The put methods upsert the given key and replaces the ttl when updated.

      Parameters

      • key: string
      • value: TType
      • Optionalsettings: CacheWriteSettings
        • Optionaljitter?: number

          Random jitter factor (0-1) to add variance to expiration times. Prevents thundering herd problems when many entries expire simultaneously. A value of 0.1 adds ±10% randomness to the TTL.

        • Optionalttl?: ITimeSpan | null

          Time-to-live (TTL) duration for cached entries. When set, entries will automatically expire after this duration. Pass null to cache entries without automatic expiration.

      Returns Promise<boolean>

      Returns true if the key where replaced otherwise false is returned.

  • remove:function
    • The remove method removes the given key.

      Parameters

      • key: string

      Returns Promise<boolean>

      Returns true if the key is found otherwise false is returned.

  • removeMany:function
    • The removeMany method removes many keys.

      Parameters

      • keys: Iterable<string, any, any>

        The param items can be a string or an Iterable of strings. If the param items are an Iterable, it will be joined into a single string. Think of an Iterable as representing a path.

      Returns Promise<boolean>

      Returns true if one of the keys where deleted otherwise false is returned.

  • removeOrFail:function
    • The removeOrFail method removes the given key. Throws an error if the key is not found.

      Parameters

      • key: string

      Returns Promise<void>

  • update:function
    • The update method updates the given key with given value.

      Parameters

      Returns Promise<boolean>

      Returns true if the key where updated otherwise false will be returned.

  • updateOrFail:function
    • The updateOrFail method updates the given key with given value. Thorws error if the key is not found.

      Parameters

      Returns Promise<void>