Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface EdgeCacheOptions

Options for controlling caching behavior at edge

Hierarchy

  • EdgeCacheOptions

Index

Properties

Optional forcePrivateCaching

forcePrivateCaching: undefined | false | true

Allows you to force caching of responses marked as private in their cache-control header. This option must be used with utmost care to avoid leaking private information.

Example

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

 new Router()
   .match('/private/path', ({ cache }) => {
     cache({
       edge: {
         maxAgeSeconds: 60 * 60,
         key: new CustomCacheKey()
           .addCookie('session'),
         forcePrivateCaching: true,
       }
     })
   })

Optional key

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 '@xdn/core/router'

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

Optional maxAgeSeconds

maxAgeSeconds: undefined | number

The maximum number of seconds that a response is served from the cache until it is considered stale. Unless staleWhileRevalidate is specified, stale responses will not be returned to the browser.

Optional staleWhileRevalidateSeconds

staleWhileRevalidateSeconds: undefined | number

Extends the duration that a response will be served from the cache after it has become stale. When using staleWhileRevalidate, if the XDN receives a request for a stale asset, the cached response will be served and a fresh response will be concurrently fetch so that it can be served for future requests. The stale response will continue to be served until the fresh fetched.

Generated using TypeDoc