/** * Next.js 16 Cache Handler Types * Based on: https://nextjs.org/docs/app/api-reference/config/next-config-js/cacheHandler */ /** * Prefix for implicit tags generated by Next.js (system-generated tags for ISR) */ export declare const IMPLICIT_TAG_PREFIX = "_N_T_"; /** * Cache entry value types supported by Next.js */ export type CacheValue = { kind: "ROUTE"; html: string; pageData: Record; status?: number; headers?: Record; } | { kind: "PAGE"; html: string; pageData: Record; status?: number; headers?: Record; } | { kind: "FETCH"; data: { headers: Record; body: string; status: number; url: string; }; revalidate: number | false; } | { kind: "IMAGE"; etag: string; buffer: Buffer; extension: string; isMiss?: boolean; isStale?: boolean; }; /** * Lifespan parameters for cache entries * All time values are in SECONDS (not milliseconds) */ export interface LifespanParameters { /** * Timestamp when entry was last modified (seconds since epoch) */ lastModifiedAt: number; /** * Timestamp when entry becomes stale (seconds since epoch) */ staleAt: number; /** * Timestamp when entry expires (seconds since epoch) */ expireAt: number; /** * Age in seconds until entry becomes stale */ staleAge: number; /** * Age in seconds until entry expires */ expireAge: number; /** * Original revalidate value from Next.js */ revalidate: number | false | undefined; } /** * Internal cache handler value with metadata * This is what handlers store internally */ export interface CacheHandlerValue { /** * Timestamp of last modification (milliseconds since epoch) */ lastModified: number; /** * Lifespan/TTL parameters (null means no expiration) */ lifespan: LifespanParameters | null; /** * Tags for cache invalidation (both explicit and implicit) */ tags: readonly string[]; /** * The actual cache value */ value: CacheValue; } /** * Context provided when setting cache entries */ export interface CacheHandlerContext { /** * Tags for cache invalidation */ tags?: string[]; /** * Revalidation period in seconds, or false to disable */ revalidate?: number | false; /** * Soft tags (for Next.js internal use) */ softTags?: string[]; } /** * Metadata passed to get() method */ export interface CacheHandlerGetMeta { /** * Implicit tags (system-generated) for this request */ implicitTags: string[]; } /** * Return type for cache handler get() method * Matches Next.js CacheHandlerValue structure */ export interface CacheHandlerGetResult { /** * The actual cache value (ROUTE, PAGE, FETCH, or IMAGE) */ value: CacheValue | null; /** * Timestamp of last modification (milliseconds since epoch) */ lastModified?: number; /** * Age of the cache entry in milliseconds */ age?: number; /** * Cache state metadata (for debugging) */ cacheState?: string; } /** * Cache handler interface that must be implemented */ export interface CacheHandler { /** * Handler name (for debugging/logging) */ name: string; /** * Get a cache entry by key * Returns an object with the cache value and metadata */ get(key: string, meta?: CacheHandlerGetMeta): Promise; /** * Set a cache entry */ set(key: string, value: CacheValue, context?: CacheHandlerContext): Promise; /** * Revalidate cache entries by tag * @param tag - Cache tag to revalidate * @param profile - Optional revalidation profile ("max" or custom profile name) or object with expire time */ revalidateTag(tag: string, profile?: string | { expire?: number; }): Promise; /** * Delete a cache entry by key (optional) */ delete?(key: string): Promise; } /** * Cache handler constructor parameters */ export interface CacheHandlerOptions { /** * Next.js configuration */ _appDir?: string; _pagesDir?: string; _requestHeaders?: Record; flushToDisk?: boolean; experimental?: { ppr?: boolean; }; } //# sourceMappingURL=types.d.ts.map