mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Refs #21012 -- Removed unnecessary _create_cache() hook.
This removes unused (since d038c547b5
)
workaround to load a cache backend with its dotted import path and
moves remaining logic to the CacheHandler.
Thanks Tim Graham for the review.
This commit is contained in:
parent
85729545f1
commit
148702e725
37
django/core/cache/__init__.py
vendored
37
django/core/cache/__init__.py
vendored
@ -29,31 +29,6 @@ __all__ = [
|
|||||||
DEFAULT_CACHE_ALIAS = 'default'
|
DEFAULT_CACHE_ALIAS = 'default'
|
||||||
|
|
||||||
|
|
||||||
def _create_cache(backend, **kwargs):
|
|
||||||
try:
|
|
||||||
# Try to get the CACHES entry for the given backend name first
|
|
||||||
try:
|
|
||||||
conf = settings.CACHES[backend]
|
|
||||||
except KeyError:
|
|
||||||
try:
|
|
||||||
# Trying to import the given backend, in case it's a dotted path
|
|
||||||
import_string(backend)
|
|
||||||
except ImportError as e:
|
|
||||||
raise InvalidCacheBackendError("Could not find backend '%s': %s" % (
|
|
||||||
backend, e))
|
|
||||||
location = kwargs.pop('LOCATION', '')
|
|
||||||
params = kwargs
|
|
||||||
else:
|
|
||||||
params = {**conf, **kwargs}
|
|
||||||
backend = params.pop('BACKEND')
|
|
||||||
location = params.pop('LOCATION', '')
|
|
||||||
backend_cls = import_string(backend)
|
|
||||||
except ImportError as e:
|
|
||||||
raise InvalidCacheBackendError(
|
|
||||||
"Could not find backend '%s': %s" % (backend, e))
|
|
||||||
return backend_cls(location, params)
|
|
||||||
|
|
||||||
|
|
||||||
class CacheHandler:
|
class CacheHandler:
|
||||||
"""
|
"""
|
||||||
A Cache Handler to manage access to Cache instances.
|
A Cache Handler to manage access to Cache instances.
|
||||||
@ -75,8 +50,16 @@ class CacheHandler:
|
|||||||
raise InvalidCacheBackendError(
|
raise InvalidCacheBackendError(
|
||||||
"Could not find config for '%s' in settings.CACHES" % alias
|
"Could not find config for '%s' in settings.CACHES" % alias
|
||||||
)
|
)
|
||||||
|
params = settings.CACHES[alias].copy()
|
||||||
cache = _create_cache(alias)
|
backend = params.pop('BACKEND')
|
||||||
|
location = params.pop('LOCATION', '')
|
||||||
|
try:
|
||||||
|
backend_cls = import_string(backend)
|
||||||
|
except ImportError as e:
|
||||||
|
raise InvalidCacheBackendError(
|
||||||
|
"Could not find backend '%s': %s" % (backend, e)
|
||||||
|
)
|
||||||
|
cache = backend_cls(location, params)
|
||||||
self._caches.caches[alias] = cache
|
self._caches.caches[alias] = cache
|
||||||
return cache
|
return cache
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user