Пример #1
0
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
Пример #2
0
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
Пример #3
0
 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]
Пример #4
0
 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
Пример #5
0
 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
Пример #6
0
    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']
Пример #7
0
    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"]
Пример #8
0
    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']