UNPKG

rwsdk

Version:

Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime

69 lines (68 loc) 3.11 kB
export interface NavigationCacheEnvironment { isSecureContext: boolean; origin: string; caches?: CacheStorage; fetch: typeof fetch; } /** * Interface for a single cache instance, mirroring the Cache API. */ export interface NavigationCache { put(request: Request, response: Response): Promise<void>; match(request: Request): Promise<Response | undefined>; } /** * Interface for cache storage, mirroring the CacheStorage API. */ export interface NavigationCacheStorage { open(cacheName: string): Promise<NavigationCache>; delete(cacheName: string): Promise<boolean>; keys(): Promise<string[]>; } /** * Creates a default NavigationCacheStorage implementation that wraps the browser's CacheStorage API. * This maintains the current generation-based cache naming and eviction logic. */ export declare function createDefaultNavigationCacheStorage(env?: NavigationCacheEnvironment): NavigationCacheStorage | undefined; /** * Preloads the RSC navigation response for a given URL into the Cache API. * * This issues a GET request with the `__rsc` query parameter set, and, on a * successful response, stores it in a versioned Cache using `cache.put`. * * See MDN for Cache interface semantics: * https://developer.mozilla.org/en-US/docs/Web/API/Cache */ export declare function preloadNavigationUrl(rawUrl: URL | string, env?: NavigationCacheEnvironment, cacheStorage?: NavigationCacheStorage): Promise<void>; /** * Attempts to retrieve a cached navigation response for the given URL. * * Returns the cached Response if found, or undefined if not cached or if * CacheStorage is unavailable. */ export declare function getCachedNavigationResponse(rawUrl: URL | string, env?: NavigationCacheEnvironment, cacheStorage?: NavigationCacheStorage): Promise<Response | undefined>; /** * Cleans up old generation caches for the current tab. * * This should be called after navigation commits to evict cache entries from * previous navigations. It runs asynchronously via requestIdleCallback or * setTimeout to avoid blocking the critical path. */ export declare function evictOldGenerationCaches(env?: NavigationCacheEnvironment, cacheStorage?: NavigationCacheStorage): Promise<void>; /** * Increments the generation counter and schedules cleanup of old caches. * * This should be called after navigation commits to mark the current generation * as complete and prepare for the next navigation cycle. */ export declare function onNavigationCommit(env?: NavigationCacheEnvironment, cacheStorage?: NavigationCacheStorage): void; /** * Scan the document for `<link rel="prefetch" href="...">` elements that point * to same-origin paths and prefetch their RSC navigation responses into the * Cache API. * * This is invoked after client navigations to warm the navigation cache in * the background. We intentionally keep Cache usage write-only for now; reads * still go through the normal fetch path. */ export declare function preloadFromLinkTags(doc?: Document, env?: NavigationCacheEnvironment, cacheStorage?: NavigationCacheStorage): Promise<void>;