import type { Middleware } from "@nifrajs/core/server"; import { type MaybePromise } from "./_utils.js"; export interface CachedResponse { readonly status: number; readonly statusText: string; readonly headers: readonly [string, string][]; readonly body: Uint8Array; readonly expiresAt: number; readonly storedAt: number; } export interface ResponseCacheStore { get(key: string): MaybePromise; set(key: string, response: CachedResponse): MaybePromise; delete?(key: string): MaybePromise; } export interface MemoryResponseCacheOptions { /** Maximum entries retained. Default `1000`. Oldest entries are evicted first. */ readonly maxEntries?: number; /** Allow in-process cache in production. Off by default because it is per-instance. */ readonly allowInProduction?: boolean; } export declare class MemoryResponseCache implements ResponseCacheStore { private readonly entries; private readonly maxEntries; constructor(options?: MemoryResponseCacheOptions); get(key: string): CachedResponse | undefined; set(key: string, response: CachedResponse): void; delete(key: string): void; } export interface CacheOptions { readonly store: ResponseCacheStore; /** Time to live in milliseconds. */ readonly ttlMs: number; /** Methods cached. Default `["GET", "HEAD"]`. */ readonly methods?: readonly string[]; /** Status predicate. Default: `200` only. */ readonly status?: (status: number) => boolean; /** Header names included in the cache key and emitted in `Vary`. */ readonly vary?: readonly string[]; /** Custom cache key. Receives the normalized `vary` headers through the request itself. */ readonly key?: (request: Request) => string; /** Maximum response bytes to store. Default `1_000_000`. Larger responses pass through. */ readonly maxBytes?: number; /** Respect request `Cache-Control: no-cache/no-store`. Default `true`. */ readonly respectRequestCacheControl?: boolean; /** Respect response `Cache-Control: private/no-store`. Default `true`. */ readonly respectResponseCacheControl?: boolean; /** Cache responses with `Set-Cookie`. Default `false`. */ readonly cacheSetCookie?: boolean; /** Cache responses to requests bearing `Authorization` or `Cookie` even when the response is not * explicitly `Cache-Control: public` (or `s-maxage`). Default `false`: a shared cache must not store a * personalized response (RFC 9111 ยง3.5), or it would be replayed to other users. Leave this off unless * the cached route is genuinely the same for every caller. */ readonly cacheAuthenticated?: boolean; /** Credential headers that make a request private. Defaults to Authorization, Cookie, and x-api-key. */ readonly authenticatedHeaders?: readonly string[]; /** Response header for cache status. Default `"x-nifra-cache"`; set `false` to disable. */ readonly cacheStatusHeader?: string | false; } /** * Full response cache for small, cacheable responses. Use a shared `store` in production. The * middleware honors `Cache-Control` by default, avoids `Set-Cookie`, caps stored bytes, emits `Age`, * and keeps `Vary` headers aligned with the cache key. */ export declare function cache(options: CacheOptions): Middleware; export declare const responseCache: typeof cache; //# sourceMappingURL=cache.d.ts.map