Jump to >

djblets.cache.backend_compat

Compatibility functions for older Django cache backend configuration.

These functions are used to maintain compatibility or transition settings from older versions of Django.

normalize_cache_backend(cache_backend, cache_name='default')[source]

Return a new-style CACHES dictionary from any given cache_backend.

Over time, Django has had support for two formats for a cache backend. The old-style CACHE_BACKEND string, and the new-style CACHES dictionary.

This function will accept either as input and return a dictionary containing a single normalized entry for the given cache backend. This can be merged into the existing CACHES setting.

If a CACHES dictionary is passed, the “default” cache will be the result.

Parameters:
  • cache_backend (dict or str) – The new-style or old-style cache backend dictionary or str to normalize.
  • cache_name (str) – The name of the cache backend to look up in cache_backend, if a new-style dictionary is provided.
Returns:

A new-style cache backend dictionary containing the single cache backend referenced. If there were any parsing issues, an empty dictionary will be returned.