learn_cache_key
Learn what headers to take into account for some request URL from the response object. Store those headers in a global URL registry so that later access to that URL will know what headers to take into account without building the response object itself. The headers are named in the Vary header of the response, but we want to prevent response generation. The list of headers to use for cache key generation is stored in the same cache as the pages themselves. If the cache ages some data out of the cache, this just means that we have to build the response once to get at the Vary header and so at the list of headers to use for the cache key.
def learn_cache_key(
request: HttpRequest,
response: HttpResponse,
cache_timeout: integer = None,
key_prefix: string = None,
cache: BaseCache = None
) - > string
Learn what headers to take into account for some request URL from the response object. Store those headers in a global URL registry so that later access to that URL will know what headers to take into account without building the response object itself. The headers are named in the Vary header of the response, but we want to prevent response generation.
Parameters
| Name | Type | Description |
|---|---|---|
| request | HttpRequest | The current request object used to generate the base cache header key. |
| response | HttpResponse | The response object containing the Vary header used to determine which request headers affect the cache key. |
| cache_timeout | integer = None | The number of seconds the cache key mapping should remain valid in the cache; defaults to the middleware's configured duration. |
| key_prefix | string = None | A string to prepend to the cache key to prevent collisions between different sites or environments. |
| cache | BaseCache = None | The specific cache backend instance where the header list should be stored; defaults to the middleware's configured alias. |
Returns
| Type | Description |
|---|---|
string | The generated cache key for the specific request, incorporating the identified Vary headers and the request method. |