Interface LruIdbConfig

Configuration parameters for LruIdb

interface LruIdbConfig {
    cleanUpOrphanedPeriod?: number;
    copyOnInsert?: boolean;
    copyOnReturn?: boolean;
    databaseName?: string;
    deepCopy?: ((object: any) => any);
    evictionPeriod?: number;
    indexedDB?: {
        databaseFactory: IDBFactory;
        keyRange: any;
    };
    maxItems?: number;
    memoryConfig?: boolean | {
        maxItemsInMemory?: number;
        numMemoryItemsToPurge?: number;
    };
    numItemsToPurge?: number;
    persistencePeriod?: number;
    tablePrefix?: string;
    tablePrefixesUsed?: string[];
}

Properties

cleanUpOrphanedPeriod?: number

Check for mismatches between data stored and access times every x milliseconds. Default: 300_000 = 5min

copyOnInsert?: boolean

Copy values upon insertion. The function used to copy values is structuredClone, unless a custom deepCopy function is provided.

If this is false and items are kept in memory (which can happen due to periodic persistence, see persistencePeriod, and/or due to memoryConfig), then the caller should avoid modifying objects that have been passed to the cache.

Default is false.

copyOnReturn?: boolean

Return copies of the stored values if they come from memory, so that the caller can modify them without impacting the stored values (there is no need to copy values restored from persistence). The function used to copy values is structuredClone, unless a custom deepCopy function is provided.

If this is false and items are kept in memory (which can happen due to periodic persistence, see persistencePeriod, and/or due to memoryConfig), then the caller should avoid modifying objects returned from the cache.

Default is false.

databaseName?: string

Default: "LruIdbItemsCache"

deepCopy?: ((object: any) => any)

Only relevant if copyOnReturn is true or copyOnInsert is true. By default it uses the global structuredClone function.

Type declaration

    • (object): any
    • Parameters

      • object: any

      Returns any

evictionPeriod?: number

Batch eviction checks and operations. If this is set to a positive value, data eviction runs at most that often. In the meantime, the cache may grow beyond its specified capacity. If set to 0, items are deleted on every set operation if the cache is full, which may impede performance. Default: 60_000 = 1min

indexedDB?: {
    databaseFactory: IDBFactory;
    keyRange: any;
}

Mostly for testing. Default: globalThis.indexedDB

maxItems?: number

Maximum number of items to be kept in the store. Note that this is not enforced strictly, a clean up operation takes place regularly to purge the cache from old entries.

Default: 1000. Set to 0 to disable lru disposal and keep everything until deleted explicitly.

memoryConfig?: boolean | {
    maxItemsInMemory?: number;
    numMemoryItemsToPurge?: number;
}

Keep items in memory?

Type declaration

  • OptionalmaxItemsInMemory?: number

    Maximum number of items in memory. Default: 100.

  • OptionalnumMemoryItemsToPurge?: number

    Default: maxItemsInMemory/4

numItemsToPurge?: number

In case the LruIdbConfig.maxItems threshold is violated, this number of entries will be removed from the cache.

Default: 50 or maxItems/4, whichever is smaller.

persistencePeriod?: number

Persist lru information every X milliseconds. If set to 0, periodic persistence is disabled. Default: 15_000 = 15s

tablePrefix?: string

Default: "". The prefix will be prepended to "Items" and "AccessTimes" to generate the names for the two IndexedDB object stores used.

tablePrefixesUsed?: string[]

When using multiple caches with different table names but the same database in a single app, then it is more efficient to pass all the tables here, so they can be created right at the start. This is not strictly required, however, if a table for some cache is missing it will be created later, resulting in an IndexedDB version update.