Belin.io Core
    Preparing search index...

    Interface ICache

    Represents a cache.

    interface ICache {
        clear: () => Promise<void>;
        delete: (key: string) => Promise<void>;
        get: <T>(key: string) => Promise<null | T>;
        getOrCreate: <T>(
            key: string,
            factory: () => Promise<T>,
            duration?: number,
        ) => Promise<T>;
        has: (key: string) => Promise<boolean>;
        set: (key: string, value: unknown, duration?: number) => Promise<ICache>;
    }

    Implemented by

    Index

    Properties

    clear: () => Promise<void>

    Removes all entries from this cache.

    Type declaration

      • (): Promise<void>
      • Returns Promise<void>

        Resolves when this cache has been cleared.

    delete: (key: string) => Promise<void>

    Removes the value associated with the specified key.

    Type declaration

      • (key: string): Promise<void>
      • Parameters

        • key: string

          The cache key.

        Returns Promise<void>

        Resolves when the value has been removed.

    get: <T>(key: string) => Promise<null | T>

    Gets the value associated with the specified key.

    Type declaration

      • <T>(key: string): Promise<null | T>
      • Type Parameters

        • T

        Parameters

        • key: string

          The cache key.

        Returns Promise<null | T>

        The cached value, or null if the key does not exist.

    getOrCreate: <T>(
        key: string,
        factory: () => Promise<T>,
        duration?: number,
    ) => Promise<T>

    Gets the value associated with the specified key if it exists, or generates a new entry using the value from the given factory.

    Type declaration

      • <T>(key: string, factory: () => Promise<T>, duration?: number): Promise<T>
      • Type Parameters

        • T

        Parameters

        • key: string

          The cache key.

        • factory: () => Promise<T>

          The factory that creates the value if the key does not exist in the cache.

        • Optionalduration: number

          The number of seconds in which the cached value will expire.

        Returns Promise<T>

        The cached value.

    has: (key: string) => Promise<boolean>

    Gets a value indicating whether this cache contains the specified key.

    Type declaration

      • (key: string): Promise<boolean>
      • Parameters

        • key: string

          The cache key.

        Returns Promise<boolean>

        true if this cache contains the specified key, otherwise false.

    set: (key: string, value: unknown, duration?: number) => Promise<ICache>

    Associates a given value with the specified key.

    Type declaration

      • (key: string, value: unknown, duration?: number): Promise<ICache>
      • Parameters

        • key: string

          The cache key.

        • value: unknown

          The value to be cached.

        • Optionalduration: number

          The number of seconds in which the cached value will expire.

        Returns Promise<ICache>

        This instance.