Type Alias ICacheBase<TType>

ICacheBase: {
    add(key: string, value: TType, ttl?: null | ITimeSpan): Task<boolean>;
    clear(): Task<void>;
    decrement(key: string, value?: Extract<TType, number>): Task<boolean>;
    exists(key: string): Task<boolean>;
    get(key: string): Task<null | TType>;
    getAndRemove(key: string): Task<null | TType>;
    getOr(
        key: string,
        defaultValue: AsyncLazyable<NoneFunc<TType>>,
    ): Task<TType>;
    getOrAdd(
        key: string,
        valueToAdd: AsyncLazyable<NoneFunc<TType>>,
        ttl?: null | ITimeSpan,
    ): Task<TType>;
    getOrFail(key: string): Task<TType>;
    increment(key: string, value?: Extract<TType, number>): Task<boolean>;
    missing(key: string): Task<boolean>;
    put(key: string, value: TType, ttl?: null | ITimeSpan): Task<boolean>;
    remove(key: string): Task<boolean>;
    removeMany(keys: Iterable<string, any, any>): Task<boolean>;
    update(key: string, value: TType): Task<boolean>;
}

The ICacheBase contract defines a way for 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

        can be a string or an Iterable of strings. If it's an Iterable, it will be joined into a single string. Think of an Iterable as representing a path.

      • value: TType
      • Optionalttl: null | ITimeSpan

        If null is passed, the item will not expire.

      Returns Task<boolean>

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

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

      Parameters

      • key: string

        can be a string or an Iterable of strings. If it's an Iterable, it will be joined into a single string. Think of an Iterable as representing a path.

      • Optionalvalue: Extract<TType, number>

        If not defined then it will be defaulted to 1.

      Returns Task<boolean>

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

      TypeError

  • exists:function
    • The exists method returns true when key is found otherwise false will be returned.

      Parameters

      • key: string

        can be a string or an Iterable of strings. If it's an Iterable, it will be joined into a single string. Think of an Iterable as representing a path.

      Returns Task<boolean>

  • get:function
    • The get method returns the value when key is found otherwise null will be returned.

      Parameters

      • key: string

        can be a string or an Iterable of strings. If it's an Iterable, it will be joined into a single string. Think of an Iterable as representing a path.

      Returns Task<null | TType>

  • 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

        can be a string or an Iterable of strings. If it's an Iterable, it will be joined into a single string. Think of an Iterable as representing a path.

      Returns Task<null | TType>

  • getOr:function
  • getOrAdd:function
  • getOrFail:function
    • The getOrFail method returns the value when key is found otherwise an error will be thrown.

      Parameters

      • key: string

        can be a string or an Iterable of strings. If it's an Iterable, it will be joined into a single string. Think of an Iterable as representing a path.

      Returns Task<TType>

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

      Parameters

      • key: string

        can be a string or an Iterable of strings. If it's an Iterable, it will be joined into a single string. Think of an Iterable as representing a path.

      • Optionalvalue: Extract<TType, number>

        If not defined then it will be defaulted to 1.

      Returns Task<boolean>

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

      TypeError

  • missing:function
    • The missing method returns true when key is not found otherwise false will be returned.

      Parameters

      • key: string

        can be a string or an Iterable of strings. If it's an Iterable, it will be joined into a single string. Think of an Iterable as representing a path.

      Returns Task<boolean>

  • put:function
    • The put method replaces th given key with the given value and ttl if the key exists othwerwise it will add the given value with the given ttl.

      Parameters

      • key: string

        can be a string or an Iterable of strings. If it's an Iterable, it will be joined into a single string. Think of an Iterable as representing a path.

      • value: TType
      • Optionalttl: null | ITimeSpan

        If null is passed, the item will not expire.

      Returns Task<boolean>

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

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

      Parameters

      • key: string

        can be a string or an Iterable of strings. If it's an Iterable, it will be joined into a single string. Think of an Iterable as representing a path.

      Returns Task<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 Task<boolean>

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

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

      Parameters

      • key: string

        can be a string or an Iterable of strings. If it's an Iterable, it will be joined into a single string. Think of an Iterable as representing a path.

      • value: TType

      Returns Task<boolean>

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