Belin.io Core
    Preparing search index...

    Implements a cache using files.

    Implements

    Index

    Constructors

    Properties

    Methods

    Constructors

    • Creates a new file cache.

      Parameters

      • path: string

        The path of the directory to store cache files.

      • options: Partial = {}

        An object providing values to initialize this instance.

      Returns FileCache

    Properties

    path: string

    The path of the directory to store cache files.

    Methods

    • Removes all entries from this cache.

      Returns Promise<void>

      Resolves when this cache has been cleared.

    • Removes the value associated with the specified key.

      Parameters

      • key: string

        The cache key.

      Returns Promise<void>

      Resolves when the value has been removed.

    • Gets the value associated with the specified key.

      Type Parameters

      • T

      Parameters

      • key: string

        The cache key.

      Returns Promise<null | T>

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

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

      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.

      • duration: number = -1

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

      Returns Promise<T>

      The cached value.

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

      Parameters

      • key: string

        The cache key.

      Returns Promise<boolean>

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

    • Associates a given value with the specified key.

      Parameters

      • key: string

        The cache key.

      • value: unknown

        The value to be cached.

      • duration: number = -1

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

      Returns Promise<FileCache>

      This instance.