Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RenewableCache<Key, Value, ArgumentsBundle>

Asynchronous implementation of the Cache, which auto fills itself by using KeyRetriever.
In case key was requested and it's missing, retriever will be called to obtain it's value which will be saved in the cache and then returned to client.
If you don't want to pass each time same arguments bundle for cache operations, you can provide a KeyConfigProvider. This function will be called each time an operation is performed on key. Returned arguments bundle will be forwarded to the underlying Cache implementation. This is especially useful for Cache.get operation which needs to automatically insert missing keys and use an arguments bundle for them.

Type parameters

  • Key

    Type of the key.

  • Value

    Type of the value.

  • ArgumentsBundle

    Type of the arguments bundle.

Hierarchy

  • RenewableCache

Implements

  • Cache<Key, Value, ArgumentsBundle, "promise", PromiseHolder<Undefinable<Value>>>

Constructors

Accessors

Methods

Constructors

constructor

  • new RenewableCache<Key, Value, ArgumentsBundle>(options: RenewableCacheOptions<Key, Value, ArgumentsBundle>): RenewableCache<Key, Value, ArgumentsBundle>
  • Type parameters

    • Key

    • Value

    • ArgumentsBundle

    Parameters

    • options: RenewableCacheOptions<Key, Value, ArgumentsBundle>

    Returns RenewableCache<Key, Value, ArgumentsBundle>

Accessors

size

  • get size(): number
  • Number of cache entries.

    Returns number

Methods

clear

  • clear(): void
  • Clear all cache entries.
    After successful clear, CacheEvent.FLUSH event will be emitted.

    Returns void

del

  • del(key: Key): boolean
  • Delete key and it's associated value.
    After successful deletion, CacheEvent.DELETE event will be emitted.

    Parameters

    • key: Key

      Name of the key.

    Returns boolean

get

  • get(key: Key, argsBundle?: ArgumentsBundle): Promise<undefined | Value>
  • Get the value associated with key.

    Parameters

    • key: Key

      Name of the key.

    • Optional argsBundle: ArgumentsBundle

      Bundle of arguments passed by client for this operation.

    Returns Promise<undefined | Value>

has

  • has(key: Key): boolean
  • Check if key is present in the cache.

    Parameters

    • key: Key

      Name of the key.

    Returns boolean

keys

  • keys(): Key[]
  • Get all cache keys.

    Returns Key[]

off

on

set

  • set(key: Key, value: Value, argsBundle?: ArgumentsBundle): void
  • Insert/update key-value pair.
    Due to auto fill nature of the cache, you can use this method explicitly set a value for the key and (maybe) overwrite the value provided by retriever.

    Parameters

    • key: Key

      Key.

    • value: Value

      Value.

    • Optional argsBundle: ArgumentsBundle

      Arguments bundle.

    Returns void