UNPKG

@rb2bv/cache-handler

Version:
68 lines (65 loc) 3.06 kB
import { CacheHandlerValue as CacheHandlerValue$1, CacheHandler } from 'next/dist/server/lib/incremental-cache'; import FileSystemCache from 'next/dist/server/lib/incremental-cache/file-system-cache'; import { CachedRedirectValue, IncrementalCachedAppPageValue, CachedImageValue, CachedFetchValue, CachedRouteValue, IncrementalCacheValue as IncrementalCacheValue$1, CachedRouteKind } from 'next/dist/server/response-cache/types'; type Override<T, U> = Omit<T, keyof U> & U; type ExtractIncrementalCacheKind<T, Kind> = T extends { kind: Kind; } ? T : never; type Revalidate = false | number; type IncrementalCachedPageValue = ExtractIncrementalCacheKind<IncrementalCacheValue$1, CachedRouteKind.PAGES>; type IncrementalCacheValue = CachedRedirectValue | IncrementalCachedPageValue | IncrementalCachedAppPageValue | CachedImageValue | CachedFetchValue | CachedRouteValue; /** * A set of time periods and timestamps for controlling cache behavior. */ type LifespanParameters = { /** * The Unix timestamp (in seconds) for when the cache entry was last modified. */ readonly lastModifiedAt: number; /** * The Unix timestamp (in seconds) for when the cache entry entry becomes stale. * After this time, the entry is considered staled and may be used. */ readonly staleAt: number; /** * The Unix timestamp (in seconds) for when the cache entry must be removed from the cache. * After this time, the entry is considered expired and should not be used. */ readonly expireAt: number; /** * Time in seconds before the cache entry becomes stale. */ readonly staleAge: number; /** * Time in seconds before the cache entry becomes expired. */ readonly expireAge: number; /** * Value from Next.js revalidate option. May be false if the page has no revalidate option or the revalidate option is set to false. */ readonly revalidate: Revalidate | undefined; }; type CacheHandlerValue = Override<CacheHandlerValue$1 & { /** * Timestamp in milliseconds when the cache entry was last modified. */ lastModified: number; /** * Tags associated with the cache entry. They are used for on-demand revalidation. */ tags: Readonly<string[]>; /** * The lifespan parameters for the cache entry. * * Null for pages with `fallback: false` in `getStaticPaths`. * Consider these pages as always fresh and never stale. */ lifespan: LifespanParameters | null; }, { value: IncrementalCacheValue | null; }>; type FileSystemCacheContext = ConstructorParameters<typeof FileSystemCache>[0]; type CacheHandlerParametersGet = Parameters<CacheHandler['get']>; type CacheHandlerParametersSet = Parameters<CacheHandler['set']>; type CacheHandlerParametersRevalidateTag = Parameters<CacheHandler['revalidateTag']>; export type { CacheHandlerValue as C, FileSystemCacheContext as F, Revalidate as R, CacheHandlerParametersGet as a, CacheHandlerParametersSet as b, CacheHandlerParametersRevalidateTag as c };