interface CacheApiMiddlewareOptions
Since 0.2.0

Options for cacheApiMiddleware.

Properties

readonly
optional
cache: ICacheApi

The cache handle. Omitted resolves caches.default from the global scope; when that is also absent — every runtime other than Cloudflare Workers — the middleware passes through instead of throwing.

readonly
optional
key: (ctx: IRequestContext) => string

Builds the cache key from the request. Omitted uses the full request URL, which is what the platform's own cache keys on.

readonly
optional
bypass: (ctx: IRequestContext) => boolean

Returning true skips the cache entirely for this request.

readonly
optional
cacheableStatuses: readonly number[]

Statuses worth caching. Defaults to [200]. Does not override the platform's unconditional refusal of 206.

readonly
optional
ttlSeconds: number

Adds Cache-Control: public, max-age=<n> to the stored copy when the response carries no Cache-Control of its own. The edge honors the stored response's own directive, so without one an entry has no freshness lifetime and is of little use. The client's response is left untouched.

Usage

import { type CacheApiMiddlewareOptions } from "cloudflare-plugin/src/index.ts";