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 Non
(request, key_prefix=None, method="GET", cache=None)
| 376 | |
| 377 | |
| 378 | def get_cache_key(request, key_prefix=None, method="GET", cache=None): |
| 379 | """ |
| 380 | Return a cache key based on the request URL and query. It can be used |
| 381 | in the request phase because it pulls the list of headers to take into |
| 382 | account from the global URL registry and uses those to build a cache key |
| 383 | to check against. |
| 384 | |
| 385 | If there isn't a headerlist stored, return None, indicating that the page |
| 386 | needs to be rebuilt. |
| 387 | """ |
| 388 | if key_prefix is None: |
| 389 | key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX |
| 390 | cache_key = _generate_cache_header_key(key_prefix, request) |
| 391 | if cache is None: |
| 392 | cache = caches[settings.CACHE_MIDDLEWARE_ALIAS] |
| 393 | headerlist = cache.get(cache_key) |
| 394 | if headerlist is not None: |
| 395 | return _generate_cache_key(request, method, headerlist, key_prefix) |
| 396 | else: |
| 397 | return None |
| 398 | |
| 399 | |
| 400 | def learn_cache_key(request, response, cache_timeout=None, key_prefix=None, cache=None): |