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')
.addDevice()
edge: {
maxAgeSeconds: 60 * 60
}
})
})

Hierarchy

  • default

Constructors

Methods

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

    Returns

    A self-reference, suitable for chaining.

    Returns default

  • Adds a cookie to the cache key. This will have no effect on service worker cache.

    Returns

    A self-reference, suitable for chaining.

    Parameters

    • name: string

      The name of the cookie

    Returns default

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

    Returns

    A self-reference, suitable for chaining.

    Returns default

  • Adds a request header to the cache key. This will have no effect on service worker cache.

    Returns

    A self-reference, suitable for chaining.

    Parameters

    • name: string

      The name of the request header

    Returns default

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

    Returns

    A self-reference, suitable for chaining.

    Returns default

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

    Returns

    A self-reference, suitable for chaining.

    Returns default

  • Parameters

    Returns void

  • Excludes the entire query string from the cache key.

    Returns

    A self-reference, suitable for chaining.

    Returns default

  • 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.

    Returns

    A self-reference, suitable for chaining.

    Parameters

    • Rest ...names: string[]

      The names of the query parameters to whitelist

    Returns default

  • 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.

    Returns

    A self-reference, suitable for chaining.

    Parameters

    • Rest ...names: string[]

      The names of the query parameters to blacklist

    Returns default

  • This method is not supported, and will throw an error if called.

    Returns void

  • Removes the HTTP method from the cache key.

    Returns

    A self-reference, suitable for chaining.

    Returns default

Generated using TypeDoc