def get_cache(backend): from django.core.cache import (get_cache as django_get_cache, InvalidCacheBackendError) try: cache = django_get_cache(backend) except InvalidCacheBackendError: cache = django_get_cache('default') return cache
def get_cache(backend): from django.core.cache import ( get_cache as django_get_cache, InvalidCacheBackendError) try: cache = django_get_cache(backend) except InvalidCacheBackendError: cache = django_get_cache('default') return cache
def __call__(self, backend=None, *args, **kwargs): """Returns instance of CacheTagging class.""" backend = backend or DEFAULT_CACHE_ALIAS key = pickle.dumps((backend, args, kwargs)).encode("base64") if key not in self._caches: self._caches[key] = CacheTagging( django_get_cache(backend, *args, **kwargs) ) return self._caches[key]
def set_backend(self, new_backend): from django.core.cache import get_cache as django_get_cache if isinstance(new_backend, basestring): new_backend = django_get_cache(new_backend) self._backend = new_backend for attr in self._backend_attrs: try: delattr(self, attr) except AttributeError: pass
def __call__(self, backend=None, *args, **kwargs): """Returns instance of CacheTagging class.""" backend = backend or DEFAULT_CACHE_ALIAS key = (backend, args, frozenset(kwargs.items())) if not hasattr(self._caches, 'caches'): self._caches.caches = {} if key not in self._caches.caches: self._caches.caches['key'] = CacheTagging( django_get_cache(backend, *args, **kwargs) ) return self._caches.caches['key']
def __call__(self, backend=None, *args, **kwargs): """Returns instance of CacheTagging class.""" backend = backend or DEFAULT_CACHE_ALIAS key = (backend, args, frozenset(kwargs.items())) if not hasattr(self._caches, "caches"): self._caches.caches = {} if key not in self._caches.caches: options = getattr(settings, "CACHE_TAGGING", {}).get(backend, {}) delay = options.get("DELAY", None) nonrepeatable_reads = options.get("NONREPEATABLE_READS", False) django_backend = options.get("BACKEND", backend) self._caches.caches["key"] = CacheTagging( django_get_cache(django_backend, *args, **kwargs), delay, nonrepeatable_reads ) return self._caches.caches["key"]
def __call__(self, backend=None, *args, **kwargs): """Returns instance of CacheTagging class.""" backend = backend or DEFAULT_CACHE_ALIAS key = (backend, args, frozenset(kwargs.items())) if not hasattr(self._caches, 'caches'): self._caches.caches = {} if key not in self._caches.caches: options = getattr(settings, 'CACHE_TAGGING', {}).get(backend, {}) delay = options.get('DELAY', None) nonrepeatable_reads = options.get('NONREPEATABLE_READS', False) django_backend = options.get('BACKEND', backend) self._caches.caches['key'] = CacheTagging( django_get_cache(django_backend, *args, **kwargs), delay, nonrepeatable_reads) return self._caches.caches['key']