1.1.0 • Published 5 years ago
@p-j/eapi-middleware-cache v1.1.0
@p-j/eapi-middleware-cache
A middleware to configure cache behavior on a per route or request basis
Installation
- From the NPM registry
 
npm install @p-j/eapi-middleware-cache
# or
yarn add @p-j/eapi-middleware-cacheAPI
withCache is a Middleware Factory; it takes the following options:
export interface WithCacheOptions {
  cacheControl?: string
  cdnTtl?: number
  cacheError?: boolean
  varyHeaders?: string[]
  serverTimings?: boolean
}As noted above, none of the options are required.
cacheControlthe value to be assigned to the Cache-Control header (control the Browser Cache TTL)cdnTtlthis control the Edge Cache TTL, by default it also sets a Cache-Control of the same value, unlesscacheControlis also setcacheCacheErrorwheter or not to cache errors. Defaults to false.varyHeadersan array of Header names to be add to the Vary header (eg: 'Accept', 'Origin' ... ).serverTimings=trueadd Server-Timing header with cache interaction information. Defaults to true.
For a better understanding of how cache works in the context of Cloudflare Workers, these links may help:
And for the underlying API