Interface LruCacheIndexedDB<T>

A least-recently-used (LRU) cache for the browser, based on IndexedDB. All methods returning the cached values, such as LruCacheIndexedDB.get(key, options), reset the last access time of the respective entries, as do the setters. Methods iterating over keys, such as LruCacheIndexedDB.iterateKeys(options), do not.

interface LruCacheIndexedDB<T> {
    [asyncIterator](options?: IterationOptions): AsyncIterableIterator<string[], any, any>;
    clear(options?: CacheRequestOptions): Promise<unknown>;
    close(): Promise<unknown>;
    computedConfig(): LruIdbConfig;
    delete(keys: string | string[], options?: CacheRequestOptions): Promise<number>;
    entries(options?: IterationOptions): AsyncIterableIterator<Map<string, T>, any, any>;
    get(key: string, options?: CacheRequestOptions): Promise<undefined | T>;
    getAll(keys: string[], options?: CacheRequestOptions & {
        includeAbsent?: boolean;
    }): Promise<Map<string, undefined | T>>;
    getAllKeys(options?: CacheRequestOptions): Promise<string[]>;
    has(key: string, options?: CacheRequestOptions): Promise<boolean>;
    keys(options?: IterationOptions): AsyncIterableIterator<string[], any, any>;
    peek(key: string, options?: CacheRequestOptions): Promise<undefined | T>;
    persist(): Promise<unknown>;
    set(key: string, value: T, options?: CacheRequestOptions & CacheWriteOptions): Promise<unknown>;
    setAll(entries: Map<string, T>, options?: CacheRequestOptions & CacheWriteOptions): Promise<unknown>;
    size(options?: CacheRequestOptions): Promise<number>;
    streamEntries(options?: IterationOptions): ReadableStream<Map<string, T>>;
    streamKeys(options?: IterationOptions): ReadableStream<string[]>;
    streamValues(options?: IterationOptions): ReadableStream<T[]>;
    values(options?: IterationOptions): AsyncIterableIterator<T[], any, any>;
}

Type Parameters

  • T

Hierarchy

  • AsyncIterable<string[]>
    • LruCacheIndexedDB

Methods

  • Iterate over keys in the cache, optionally in the order of last access time.

    Parameters

    Returns AsyncIterableIterator<string[], any, any>

  • Close the cache. Note that this will trigger the persistence, so it should be good practice to close the cache explicitly before

    Returns Promise<unknown>

  • Delete one or multiple entries.

    Parameters

    Returns Promise<number>

  • See keys().

    Parameters

    Returns AsyncIterableIterator<Map<string, T>, any, any>

  • Get a cached value, if present, or undefined if not. Resets the last access time of the entry, if present.

    Parameters

    Returns Promise<undefined | T>

  • Get multiple cached values at once. Resets the last access time of the present entries.

    Parameters

    Returns Promise<Map<string, undefined | T>>

  • Retrieve all stored keys. Usually not recommended due its performance impact, prefer the streaming or iterating methods streamKeys(), keys() instead.

    Parameters

    Returns Promise<string[]>

  • Check if a key is contained in the cache. This does not change its access time.

    Parameters

    Returns Promise<boolean>

  • Iterate over keys in the cache, optionally in the order of last access time. Note that this returns batches of keys in each step, typically around 100 per batch, since this is much more performant on large caches due to the promise overhead.

    Parameters

    Returns AsyncIterableIterator<string[], any, any>

  • Like get() but does not modify the access time of the entry.

    Parameters

    Returns Promise<undefined | T>

  • If the configured persistence interval is positive, this method can be used to trigger an immediate persistence of the stored data.

    Returns Promise<unknown>

  • Returns an estimate of the number of items currently contained in the cache. Under normal conditions, this should be smaller than the specified threshold LruIdbConfig.maxItems, but it may also occasionally exceed this value.

    Parameters

    Returns Promise<number>

  • Retrieve a stream of keys, optionally in the order of last access time.

    Parameters

    Returns ReadableStream<string[]>