Options
All
  • Public
  • Public/Protected
  • All
Menu

Caches requests in memory and handles expiring them.

Type parameters

  • T

  • P: Array<unknown>

Hierarchy

  • ClientRequestCache

Index

Constructors

Methods

Constructors

constructor

  • new ClientRequestCache(ttl: number, maxSize: number, requestFunc: (key: string, ...args: P) => Promise<T>): ClientRequestCache
  • Parameters

    • ttl: number

      How old a result can be before it gets expired.

    • maxSize: number
    • requestFunc: (key: string, ...args: P) => Promise<T>

      The function to use on cache miss.

        • (key: string, ...args: P): Promise<T>
        • Parameters

          • key: string
          • Rest ...args: P

          Returns Promise<T>

    Returns ClientRequestCache

Methods

get

  • get(key: string, ...args: P): T | Promise<T>
  • Gets a result of a request from the cache, or otherwise tries to fetch the the result with this.requestFunc

    throws

    {Error} If the key is not a string.

    Parameters

    • key: string

      Key of the item to get/store.

    • Rest ...args: P

      A set of arguments to pass to the request func.

    Returns T | Promise<T>

    The request, or undefined if not retrievable.

getCachedResults

  • getCachedResults(): Map<string, { content: T; ts: number }>

Generated using TypeDoc