@p-j/eapi-middleware-cache
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@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-cache

API

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.

  • cacheControl the value to be assigned to the Cache-Control header (control the Browser Cache TTL)
  • cdnTtl this control the Edge Cache TTL, by default it also sets a Cache-Control of the same value, unless cacheControl is also set
  • cacheCacheError wheter or not to cache errors. Defaults to false.
  • varyHeaders an array of Header names to be add to the Vary header (eg: 'Accept', 'Origin' ... ).
  • serverTimings=true add 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

Package Sidebar

Install

npm i @p-j/eapi-middleware-cache

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

34.3 kB

Total Files

13

Last publish

Collaborators

  • jparker