Skip to content

Latest commit

 

History

History

eapi-middleware-cache

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

@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