@foundatiofx/fetchclient
Version:
A typed JSON fetch client with middleware support for Deno, Node and the browser.
62 lines • 2.02 kB
TypeScript
/**
* Represents a cache key used in the FetchClientCache.
*/
export type CacheKey = string[] | string;
/**
* Represents an entry in the FetchClientCache.
*/
type CacheEntry = {
key: CacheKey;
lastAccess: Date;
expires: Date;
response: Response;
};
/**
* Represents a cache for storing responses from the FetchClient.
*/
export declare class FetchClientCache {
private cache;
/**
* Sets a response in the cache with the specified key.
* @param key - The cache key.
* @param response - The response to be cached.
* @param cacheDuration - The duration for which the response should be cached (in milliseconds).
*/
set(key: CacheKey, response: Response, cacheDuration?: number): void;
/**
* Retrieves a response from the cache with the specified key.
* @param key - The cache key.
* @returns The cached response, or null if the response is not found or has expired.
*/
get(key: CacheKey): Response | null;
/**
* Deletes a response from the cache with the specified key.
* @param key - The cache key.
* @returns True if the response was successfully deleted, false otherwise.
*/
delete(key: CacheKey): boolean;
/**
* Deletes all responses from the cache that have keys beginning with the specified key.
* @param prefix - The cache key prefix.
* @returns The number of responses that were deleted.
*/
deleteAll(prefix: CacheKey): number;
/**
* Checks if a response exists in the cache with the specified key.
* @param key - The cache key.
* @returns True if the response exists in the cache, false otherwise.
*/
has(key: CacheKey): boolean;
/**
* Returns an iterator for the cache entries.
* @returns An iterator for the cache entries.
*/
values(): IterableIterator<CacheEntry>;
/**
* Clears all entries from the cache.
*/
clear(): void;
private getHash;
}
export {};
//# sourceMappingURL=FetchClientCache.d.ts.map