Type Alias ICache<TType>

ICache: IReadableCache<TType> & {
    add(key: string, value: TType, ttl?: ITimeSpan): Promise<boolean>;
    addOrFail(key: string, value: TType, ttl?: ITimeSpan): 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: TType,
        ttl?: null | ITimeSpan,
    ): 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, ttl?: ITimeSpan): Promise<boolean>;
    remove(key: string): Promise<boolean>;
    removeMany(keys: string[]): Promise<boolean>;
    removeOrFail(key: string): Promise<void>;
    update(key: string, value: TType): Promise<boolean>;
    updateOrFail(key: string, value: TType): Promise<void>;
}

The ICache 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
  • 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
    • 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.

      • Optionalttl: null | ITimeSpan

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

      Returns Promise<TType>

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

  • 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
  • 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: string[]

      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>