import { RateLimitOptions, ReactPromise } from "./promises.js"; //#region src/utils/caches.d.ts /** * Can be used to cache the result of a function call, for example for the `use` hook in React. */ declare function cacheFunction(f: F): F; type CacheStrategy = "write-only" | "read-write" | "never"; declare class AsyncCache { private readonly _fetcher; private readonly _options; private readonly _map; constructor(_fetcher: (dependencies: D) => Promise, _options?: { onSubscribe?: (key: D, refresh: () => void) => (() => void); rateLimiter?: Omit; }); private _createKeyed; getValueCache(dependencies: D): AsyncValueCache; refreshWhere(predicate: (dependencies: D) => boolean): Promise; invalidateWhere(predicate: (dependencies: D) => boolean): Promise; readonly isCacheAvailable: (key: D) => boolean; readonly getIfCached: (key: D) => ({ status: "error"; error: unknown; } & { status: "error"; }) | ({ status: "pending"; } & { progress: void; } & { status: "pending"; }) | ({ status: "ok"; data: T; } & { status: "ok"; }); readonly getOrWait: (key: D, cacheStrategy: CacheStrategy) => ReactPromise; readonly forceSetCachedValue: (key: D, value: T) => void; readonly forceSetCachedValueAsync: (key: D, value: Promise) => ReactPromise; readonly refresh: (key: D) => Promise; readonly invalidate: (key: D) => Promise; readonly onStateChange: (key: D, callback: (value: T, oldValue: T | undefined) => void) => { unsubscribe: () => void; }; readonly isDirty: (key: D) => boolean; } declare class AsyncValueCache { private readonly _options; private _store; private _pendingPromise; private _fetcher; private readonly _rateLimitOptions; private _subscriptionsCount; private _unsubscribers; private _mostRecentRefreshPromiseIndex; constructor(fetcher: () => Promise, _options?: { onSubscribe?: (refresh: () => void) => (() => void); rateLimiter?: Omit; }); isCacheAvailable(): boolean; getIfCached(): ({ status: "error"; error: unknown; } & { status: "error"; }) | ({ status: "pending"; } & { progress: void; } & { status: "pending"; }) | ({ status: "ok"; data: T; } & { status: "ok"; }); getOrWait(cacheStrategy: CacheStrategy): ReactPromise; private _set; private _setAsync; private _refetch; forceSetCachedValue(value: T): void; forceSetCachedValueAsync(value: Promise): ReactPromise; /** * If anyone is listening to the cache, refreshes the value, and sets it without invalidating the cache. */ refresh(): Promise; /** * Invalidates the cache, marking it dirty (ie. it will be refreshed on the next read). If anyone is listening to the cache, it will refresh immediately. */ invalidate(): Promise; isDirty(): boolean; _invalidateCacheSoon(): void; onStateChange(callback: (value: T, oldValue: T | undefined) => void): { unsubscribe: () => void; }; } //#endregion export { AsyncCache, cacheFunction }; //# sourceMappingURL=caches.d.ts.map