/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ /** * Three supported expiry policies: * - indefinite: entries don't expire and must be explicitly removed * - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time * - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock) * * @deprecated Moved to the `@fluidframework/core-utils` package. * @internal */ export declare type PromiseCacheExpiry = { policy: "indefinite"; } | { policy: "absolute" | "sliding"; durationMs: number; }; /** * Options for configuring the {@link PromiseCache} * * @deprecated Moved to the `@fluidframework/core-utils` package. * @internal */ export interface PromiseCacheOptions { /** Common expiration policy for all items added to this cache */ expiry?: PromiseCacheExpiry; /** If the stored Promise is rejected with a particular error, should the given key be removed? */ removeOnError?: (e: any) => boolean; } /** * A specialized cache for async work, allowing you to safely cache the promised result of some async work * without fear of running it multiple times or losing track of errors. * * @deprecated Moved to the `@fluidframework/core-utils` package. * @internal */ export declare class PromiseCache { private readonly cache; private readonly gc; private readonly removeOnError; /** * Create the PromiseCache with the given options, with the following defaults: * * expiry: indefinite, removeOnError: true for all errors */ constructor({ expiry, removeOnError, }?: PromiseCacheOptions); /** * Check if there's anything cached at the given key */ has(key: TKey): boolean; /** * Get the Promise for the given key, or undefined if it's not found. * Extend expiry if applicable. */ get(key: TKey): Promise | undefined; /** * Remove the Promise for the given key, returning true if it was found and removed */ remove(key: TKey): boolean; /** * Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key. * Returns a Promise for the added or existing async work being done at that key. * @param key - key name where to store the async work * @param asyncFn - the async work to do and store, if not already in progress under the given key */ addOrGet(key: TKey, asyncFn: () => Promise): Promise; /** * Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key. * Returns false if the cache already contained an entry at that key, and true otherwise. * @param key - key name where to store the async work * @param asyncFn - the async work to do and store, if not already in progress under the given key */ add(key: TKey, asyncFn: () => Promise): boolean; /** * Try to add the given value, without overwriting an existing cache entry at that key. * Returns a Promise for the added or existing async work being done at that key. * @param key - key name where to store the async work * @param value - value to store */ addValueOrGet(key: TKey, value: TResult): Promise; /** * Try to add the given value, without overwriting an existing cache entry at that key. * Returns false if the cache already contained an entry at that key, and true otherwise. * @param key - key name where to store the value * @param value - value to store */ addValue(key: TKey, value: TResult): boolean; } //# sourceMappingURL=promiseCache.d.ts.map