Chok’s Typescript Utilities
    Preparing search index...

    Class LocalStore

    You can create multiple LocalStores if you want, but most likely you will only need to use the default localStore instance.

    Implements

    Index

    Constructors

    • Parameters

      • storeName: string
      • Optionaloptions: { defaultExpiryMs?: number | Duration; gcIntervalMs?: number | Duration }

      Returns LocalStore

    Properties

    defaultExpiryMs: number
    gcIntervalMs: number
    gcMsStorageKey: string

    Local storage key name for the last GC completed timestamp.

    keyPrefix: string

    The prefix string for the local storage key which identifies items belonging to this namespace.

    storeName: string

    Accessors

    • get lastGcMs(): number

      Returns the ms timestamp for the last GC (garbage collection).

      Returns number

    • set lastGcMs(ms: number): void

      Set the ms timestamp for the last GC (garbage collection).

      Parameters

      • ms: number

      Returns void

    Methods

    • Returns all items as map of key to value, mainly used for debugging dumps. The type T is applied to all values, even though they might not be of type T (in the case when you store different data types in the same store).

      Type Parameters

      • T

      Returns Map<string, StoredObject<T>>

    • Generic way to iterate through all entries.

      Type Parameters

      • T

      Parameters

      • callback: (key: string, value: T, expiryMs: number, storedMs: number) => void

      Returns void

    • Get a value by key, or undefined if it does not exist.

      Type Parameters

      • T

      Parameters

      • key: string

      Returns T | undefined

    • Returns the number of items in the store. Note that getting the size requires iterating through the entire store because the items could expire at any time, and hence the size is a dynamic number.

      Returns number