Skip to main content

get_cache_key

Return a cache key based on the request URL and query. It can be used in the request phase because it pulls the list of headers to take into account from the global URL registry and uses those to build a cache key to check against. If there isn't a headerlist stored, return None, indicating that the page needs to be rebuilt.

def get_cache_key(
request: HttpRequest,
key_prefix: string = None,
method: string = "GET",
cache: BaseCache = None
) - > string

Return a cache key based on the request URL and query. It can be used in the request phase because it pulls the list of headers to take into account from the global URL registry and uses those to build a cache key to check against.

Parameters

NameTypeDescription
requestHttpRequestThe Django request object used to derive the URL and query parameters for the key.
key_prefixstring = NoneA prefix string to prepend to the cache key, defaulting to the CACHE_MIDDLEWARE_KEY_PREFIX setting.
methodstring = "GET"The HTTP method to associate with the cache key.
cacheBaseCache = NoneThe specific cache backend instance to query for header lists; defaults to the CACHE_MIDDLEWARE_ALIAS setting.

Returns

TypeDescription
stringThe generated cache key string if a header list exists, or None if the page needs to be rebuilt.