Options
All
  • Public
  • Public/Protected
  • All
Menu

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
       }
     })
   })

Hierarchy

  • CustomCacheKey

Index

Methods

addBrowser

  • addBrowser(): this
  • Specifies that requests should be cached on a per-browser basis. This will have no effect on service worker cache.

    Returns this

    A self-reference, suitable for chaining.

addCookie

  • addCookie(name: string, createGroups?: GroupCreator): this
  • Adds a cookie to the cache key. This will have no effect on service worker cache.

    Parameters

    • name: string

      The name of the cookie

    • Optional createGroups: GroupCreator

      An function that accepts a Groups instance and calls groups.group(name) to group multiple values into a single cache key component

    Returns this

    A self-reference, suitable for chaining.

addDevice

  • addDevice(): this
  • Specifies that requests should be cached on a per-device basis. This will have no effect on service worker cache.

    Returns this

    A self-reference, suitable for chaining.

addHeader

  • addHeader(name: string, createGroups?: GroupCreator): this
  • Adds a request header to the cache key. This will have no effect on service worker cache.

    Parameters

    • name: string

      The name of the request header

    • Optional createGroups: GroupCreator

      A function that accepts a Groups instance and calls groups.group(name) to group multiple values into a single cache key component

    Returns this

    A self-reference, suitable for chaining.

addIsBot

  • addIsBot(): this
  • Specifies that requests should be cached differently for bots. This will have no effect on service worker cache.

    Returns this

    A self-reference, suitable for chaining.

addVendor

  • addVendor(): this
  • Specifies that requests should be cached on a per-vendor basis. This will have no effect on service worker cache.

    Returns this

    A self-reference, suitable for chaining.

clone

excludeAllQueryParameters

  • excludeAllQueryParameters(): this
  • Excludes the entire query string from the cache key.

    Returns this

    A self-reference, suitable for chaining.

excludeAllQueryParametersExcept

  • excludeAllQueryParametersExcept(...names: string[]): this
  • Excludes all query parameters except those provided from the cache key. We also refer to this as "whitelisting" query parameters. We recommend using this method over excludeQueryParameters as it's difficult to know all of the query parameters your application might receive and unexpected query parameters can lead to significantly lower cache hit rates.

    Parameters

    • Rest ...names: string[]

      The names of the query parameters to whitelist

    Returns this

    A self-reference, suitable for chaining.

excludeQueryParameters

  • excludeQueryParameters(...names: string[]): this
  • Excludes the provided query parameters from the cache key. All other parameters will still be part of the cache key. We also refer to this as "blacklisting" query parameters.

    Parameters

    • Rest ...names: string[]

      The names of the query parameters to blacklist

    Returns this

    A self-reference, suitable for chaining.

getActions

  • getActions(): ((key: CacheKey, srcRequest: Request) => void)[]
  • Returns ((key: CacheKey, srcRequest: Request) => void)[]

removeBody

  • removeBody(): this
  • Removes the HTTP body from the cache key.

    Returns this

    A self-reference, suitable for chaining.

removeMethod

  • removeMethod(): this
  • Removes the HTTP method from the cache key.

    Returns this

    A self-reference, suitable for chaining.

toJSON

Generated using TypeDoc