Options for controlling caching behavior in the browser and at the network edge.

Hierarchy

  • CacheOptions

Properties

browser?: false | BrowserCacheOptions

Sets the caching behavior in the browser. When set to false the caching in the browser is turned off.

cacheableStatusCodes?: number[]

List of status code which are eligible for caching. Status code 200 is always cached and can't be changed.

edge?: false | EdgeCacheOptions

Sets the caching behavior at edge. When set to false the caching in the edge is turned off. This also turns off queueing of potentially cacheable requests that platform performs automatically.

Note: if know for sure that a specific GET route will never cache then you should always set edge caching to false for it as it will disable GET request coalescing making your application faster.

enableCachingMethods?: ("POST" | "PUT")[]

Enables caching for POST and PUT. GET is always cached.

ignoreOriginNoCache?: HttpStatusCode[]

Enables caching for requests with cache-control: private, no-store or no-cache header for specific status codes. see: https://docs.edg.io/guides/v7/performance/rules/features#ignore-origin-no-cache

key?: default

Allows you to split or normalize the cache space for a given route. Common use cases include:

  • serving multiple variants of the same URL based on a currency and/or language cookie.
  • caching different responses based on device type
  • ignoring all but a specific set of query parameters when looking up a response from the cache.

Example

 import { Router, CustomCacheKey } from '@edgio/core/router'

new Router()
.match('/some-path', ({ cache }) => {
cache({
key: new CustomCacheKey()
.excludeAllQueryParametersExcept('color', 'size')
.addCookie('currency')
.addCookie('location', cookie => {
cookie.group('na').byPattern('us|ca')
cookie.group('eur').byPattern('de|fr|ee')
}),
edge: {
maxAgeSeconds: 60 * 60
}
})
})

Generated using TypeDoc