Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EntryPoolCacheBackend<Key, Value, Entry>

Backend which has a pool of reusable CacheEntry. Pool can have a fixed or dynamic size. If pool has a fixed size, trying to insert keys above that size will result in an error.
Each time key is inserted, a free CacheEntry is taken from pool to hold the value. When key is deleted/expires/cleared, it's according CacheEntry is returned to pool and can be used by another key.

Type parameters

  • Key

    Type of the key.

  • Value

    Type of the value.

  • Entry: CacheEntry<Key, Value>

    Type of the cache entry.
    Defaults to CacheEntry.

Hierarchy

  • EntryPoolCacheBackend

Implements

Constructors

Accessors

Methods

Constructors

constructor

  • new EntryPoolCacheBackend<Key, Value, Entry>(capacity?: number): EntryPoolCacheBackend<Key, Value, Entry>
  • Type parameters

    Parameters

    • Optional capacity: number

      Backend capacity.
      When given, cache will not grow above capacity (i.e. will have a fixed size).
      If you omit this argument, backend will have a dynamic size.

    Returns EntryPoolCacheBackend<Key, Value, Entry>

Accessors

size

  • get size(): number

Methods

[Symbol.iterator]

  • [Symbol.iterator](): IterableIterator<[Key, Entry]>

clear

  • clear(): void

del

  • del(entry: Entry): void
  • Delete entry.

    Parameters

    • entry: Entry

      Entry that needs to be deleted.

    Returns void

get

  • get(key: Key): Undefinable<Entry>
  • Get the CacheEntry associated with key.

    Parameters

    • key: Key

      Name of the key.

    Returns Undefinable<Entry>

has

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

    Parameters

    • key: Key

      Name of the key.

    Returns boolean

keys

  • keys(): IterableIterator<Key>
  • Returns an iterable of stored keys.

    Returns IterableIterator<Key>

set

  • set(key: Key, value: Value): Entry
  • Store key with value.

                            ⚠️ WARNING ⚠️
    

    This method should not be used to overwrite value of the key!
    You need to query the entry first and update value on the entry object.

    Parameters

    • key: Key

      Name of the key.

    • value: Value

      Value associated with key.

    Returns Entry

values

  • values(): IterableIterator<Entry>
  • Returns an iterable of stored values.

    Returns IterableIterator<Entry>