Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Cache<K, T>

A locking, generic cache; used by StaticCache and the query Cache.

export
class

Cache

template

K Key type

template

T Cache data type. For good null hygiene, make sure this does not include the undefined or void types!

Type parameters

  • K

  • T

Hierarchy

  • Cache

Index

Properties

Private locks

locks: Map<K, LockManager> = new Map<K, Cache.LockManager>()

Private store

store: Map<K, T> = new Map<K, T>()

Methods

Private checkLock

  • checkLock(mgr: LockManager, lockId?: undefined | number, isWrite?: undefined | false | true): void
  • This method reports any issues with lock validity, but allows operations to proceed anyway.

    Parameters

    • mgr: LockManager
    • Optional lockId: undefined | number
    • Optional isWrite: undefined | false | true

    Returns void

clear

  • clear(): void
  • Clear all items in the cache.

    Returns void

delete

  • delete(key: K, blocking: boolean, lockId?: undefined | number): void
  • Delete an item from the cache.

    Parameters

    • key: K

      Cache key

    • blocking: boolean

      Whether to check for a lock

    • Optional lockId: undefined | number

    Returns void

get

  • get(key: K, blocking: boolean, lockId?: undefined | number): undefined | T
  • Retrieve a value from the cache

    Parameters

    • key: K

      Cache key

    • blocking: boolean

      Whether to check for a lock

    • Optional lockId: undefined | number

    Returns undefined | T

    The value that exists in the cache, or undefined.

getLock

  • getLock(key: K, lockId: number): undefined | CacheLock
  • Get the lock for a particular key, if it exists.

    Parameters

    • key: K

      Cache key

    • lockId: number

      The ID of the lock to retrieve.

    Returns undefined | CacheLock

    Mutex, if the lock exists. undefined otherwise.

Private getManagerForKey

has

  • has(key: K): boolean
  • Whether the given key exists in the cache.

    NOTE: This does not check for locking, unlike the other methods.

    Parameters

    • key: K

      Cache key

    Returns boolean

    Whether the key exists in the cache.

lock

  • lock(key: K, isWrite: boolean): Promise<CacheLock>
  • Acquire a lock against a particular key in the cache.

    Parameters

    • key: K

      Cache key

    • isWrite: boolean

      Whether the lock requestor will write to the cache using this lock.

    Returns Promise<CacheLock>

    A promise that resolves to a unique numeric ID associated with the lock.

put

  • put(key: K, value: T, blocking: boolean, lockId?: undefined | number): void
  • Insert an item into the cache.

    Parameters

    • key: K

      Cache key

    • value: T

      Value to insert

    • blocking: boolean

      Whether to check for a lock

    • Optional lockId: undefined | number

    Returns void

unlock

  • unlock(key: K, lockId: number): void
  • Release a lock, allowing other requestors to make changes to the cache.

    Parameters

    • key: K

      Cache key

    • lockId: number

      The ID of the lock to release

    Returns void

Generated using TypeDoc