UNPKG

next

Version:

The React Framework

52 lines (51 loc) 2.13 kB
import type { CacheEntry } from '../lib/cache-handlers/types'; import type { CachedFetchValue } from '../response-cache/types'; /** * A generic cache store type that provides a subset of Map functionality */ type CacheStore<T> = Pick<Map<string, T>, 'entries' | 'size' | 'get' | 'set'>; /** * A cache store specifically for fetch cache values */ export type FetchCacheStore = CacheStore<CachedFetchValue>; /** * Parses fetch cache entries into a FetchCacheStore * @param entries - The entries to parse into the store * @returns A new FetchCacheStore containing the entries */ export declare function parseFetchCacheStore(entries: Iterable<[string, CachedFetchValue]>): FetchCacheStore; /** * Stringifies a FetchCacheStore into an array of key-value pairs * @param store - The store to stringify * @returns A promise that resolves to an array of key-value pairs */ export declare function stringifyFetchCacheStore(entries: IterableIterator<[string, CachedFetchValue]>): [string, CachedFetchValue][]; /** * Serialized format for cache entries */ interface CacheCacheStoreSerialized { value: string; tags: string[]; stale: number; timestamp: number; expire: number; revalidate: number; } /** * A cache store specifically for "use cache" values that stores promises of * cache entries. */ export type UseCacheCacheStore = Pick<Map<string, Promise<CacheEntry>>, 'entries' | 'size' | 'get' | 'set'>; /** * Parses serialized cache entries into a UseCacheCacheStore * @param entries - The serialized entries to parse * @returns A new UseCacheCacheStore containing the parsed entries */ export declare function parseUseCacheCacheStore(entries: Iterable<[string, CacheCacheStoreSerialized]>): UseCacheCacheStore; /** * Stringifies a UseCacheCacheStore into an array of key-value pairs * @param store - The store to stringify * @returns A promise that resolves to an array of key-value pairs with serialized values */ export declare function stringifyUseCacheCacheStore(entries: IterableIterator<[string, Promise<CacheEntry>]>): Promise<[string, CacheCacheStoreSerialized][]>; export {};