CacheKey Object

The cacheKey object contains methods to modify a cacheKey for an HTTP request.

The cacheKey request object contains properties that optimize cached delivery by defining unique cached content. Unique cached content is typically a combination of the URL, query arguments, cookies, headers, or custom variables. cacheKey optimization ensures that the correct cached content is delivered and ultimately improves offload and performance.

The cacheKey request object contains properties specific to a given request.

👍

CacheKey request objects can only be modified during the onClientRequest event.

For more information about how to purge EdgeWorkers generated cacheKey modifications see Purge Methods.

excludeQueryString()

Sets the query string to exclude from the cache key.

📘

If you have URLs that yield different responses based on a unique path or query string, make sure you don't exclude these differences in the cache key.

// GET /search?q=something
// Host: www.example.com
request.cacheKey.excludeQueryString();
// X-True-Cache-Key: /X/XXX/www.example.com/search

includeQueryString()

Sets the query string to include as part of the cache key. This is done by default, however it is provided as an API to be reverted to the default.

// GET /search?q=something
// Host: www.example.com 
request.cacheKey.includeQueryString();
// X-True-Cache-Key: /X/XXX/www.example.com/search?q=something

includeQueryArgument()

Sets a query argument to include as part of the cache key. This property can be called multiple times to include multiple query arguments. Calling this function once excludes all query arguments not explicitly included in a query argument from the cache key. By default, the entire query string is part of the cache key. This function takes precedence over "excludeQueryString()". If both are called only the query parameters named in the includeQueryArgument property become part of the cache key.

Parameters

includeQueryArgument(name)

Review the table for information about the available parameters.

ParameterTypeDescription
nameStringName of the query argument to include in the cache key
// GET /search?q=something&r=somethingelse&s=nextthing
// Host: www.example.com
request.cacheKey.includeQueryArgument('q');
// X-True-Cache-Key: /X/XXX/www.example.com/search?q=something
// GET /search?q=something&r=somethingelse&s=nextthing
// Host: www.example.com
request.cacheKey.includeQueryArgument('q');
request.cacheKey.includeQueryArgument('s');
// X-True-Cache-Key: /X/XXX/www.example.com/search?q=something&s=nextthing

includeCookie()

Sets a cookie in the cache key. Can be called multiple times to include multiple cookies.

📘

You can only add cookies from a request generated by an end user. Cookies created in Property Manager or using setHeader in EdgeWorkers cannot be added into the cache key.

Parameters

includeCookie(name)

Review the table for information about the available parameters.

ParameterTypeDescription
nameStringName of the Cookie to include in the cache key
// GET /search
// Host: www.example.com
// Cookie: cookie1=value1;cookie2=value2;cookie3=value3
request.cacheKey.includeCookie('cookie1');
// X-True-Cache-Key: /X/XXX/www.example.com/search cid=_cookie1=value1_

includeHeader()

Sets an HTTP request header in the cache key. Can be called multiple times to include multiple headers.

📘

You can only add headers from a request generated be an end user. Headers created in Property Manager or using setHeader in EdgeWorkers cannot be added into the cache key.

Parameters

includeHeader(name)

Review the table for information about the available parameters.

ParameterTypeDescription
nameStringName of the HTTP request header to include in the cache key
// GET /search
// Host: www.example.com
// X-MyHeader: MyValue
request.cacheKey.includeHeader('X-MyHeader');
// X-True-Cache-Key: /X/XXX/www.example.com/search cid=_X-MyHeader=MyValue_

includeVariable()

Sets a Property Manager user-defined variable in the cache key. Can be called multiple times to include multiple variables.

Parameters

includeVariable(name)

Review the table for information about the available parameters.

Parameter

Type

Description

name

String

Name of the Property Manager user-defined variable. Only variables that start with a PMUSER_ prefix are available. The name of the variable must be UPPERCASE.

For more information on how to create a user-defined variable refer to the Property Manager documentation.

// GET /search
// Host: www.example.com
request.cacheKey.includeVariable('PMUSER_MYVARIABLE');
// X-True-Cache-Key: /X/XXX/www.example.com/search cid=_PMUSER_MYVARIABLE=MYVALUE_

Did this page help you?