@swishapp/browser
Version:
JS library to integrate Swish into a browser environment.
88 lines (87 loc) • 2.61 kB
TypeScript
export declare enum CacheControl {
None = "no-cache",
Minimal = "max-age=3, stale-while-revalidate=0",// 3 seconds, no stale
Short = "max-age=60, stale-while-revalidate=3600",// 1 minute, 1 hour stale
Long = "max-age=3600, stale-while-revalidate=86400"
}
export declare class FetchCache {
private readonly cacheName;
private readonly defaultCacheControl;
private readonly revalidationPromises;
private readonly inFlightRequests;
private readonly keyPrefix;
constructor(cacheName: string, defaultCacheControl: CacheControl | string, keyPrefix?: string);
/**
* Get a cached response by key
*/
get(key: string): Promise<Response | undefined>;
/**
* Set a cached response with the specified policy
*/
set(key: string, response: Response, cacheControl: CacheControl | string): Promise<void>;
/**
* Set a cached response from a fetch request
*/
fetchWithCache(input: string | URL | Request, init?: RequestInit, cacheControl?: CacheControl | string): Promise<Response>;
/**
* Delete a specific cache entry
*/
delete(key: string): Promise<boolean>;
/**
* Clear all cache entries
*/
clear(): Promise<void>;
/**
* Get all cache keys
*/
keys(): Promise<string[]>;
/**
* Check if a key exists in cache
*/
has(key: string): Promise<boolean>;
/**
* Get cache statistics
*/
getStats(): Promise<{
total: number;
}>;
/**
* Remove all expired entries from the cache
*/
cleanupExpiredEntries(): Promise<{
removed: number;
remaining: number;
}>;
/**
* Get the cache key from fetch args
*/
getCacheKey(input: string | URL | globalThis.Request, init?: RequestInit): Promise<string>;
/**
* Get the url from the fetch input
*/
getInputUrl(input: string | URL | globalThis.Request): string;
/**
* Check if a response has expired based on its Cache-Control header
*/
private isExpired;
/**
* Check if a response is stale but can be revalidated
*/
private isStaleButRevalidatable;
/**
* Revalidate a cached response in the background
*/
private revalidateInBackground;
/**
* Parse max-age value from Cache-Control header
*/
private parseMaxAge;
/**
* Parse stale-while-revalidate value from Cache-Control header
*/
private parseStaleWhileRevalidate;
/**
* Create a cacheable response with appropriate headers based on policy
*/
private createCacheableResponse;
}