def __init__(self, stale=240, expiry=None, cache=None): """ `stale` is the number of seconds before """ if isinstance(cache, basestring): self._cache = get_django_cache(cache) elif isinstance(cache, BaseCache): self._cache = cache elif cache is None: self._cache = get_django_cache(DEFAULT_CACHE_ALIAS) else: raise TypeError("cache parameter must be None, the name of a Django cache, or a BaseCache object") self.stale = stale self.expiry = expiry
def __init__(self, stale=240, expiry=None, cache=None): """ `stale` is the number of seconds before """ if isinstance(cache, basestring): self._cache = get_django_cache(cache) elif isinstance(cache, BaseCache): self._cache = cache elif cache is None: self._cache = get_django_cache(DEFAULT_CACHE_ALIAS) else: raise TypeError( "cache parameter must be None, the name of a Django cache, or a BaseCache object" ) self.stale = stale self.expiry = expiry
def get_cache(self, cache_alias=None, atomic_level=-1): if cache_alias is None: cache_alias = cachalot_settings.CACHALOT_CACHE min_level = -len(self.atomic_caches) if atomic_level < min_level: return get_django_cache(cache_alias) return self.get_atomic_cache(cache_alias, atomic_level)
def get_cache(app): """ Attempt to find a valid cache from the Celery configuration If the setting is a valid cache, just use it. Otherwise, if Django is installed, then: If the setting is a valid Django cache entry, then use that. If the setting is empty use the default cache Otherwise, if Werkzeug is installed, then: If the setting is a valid Celery Memcache or Redis Backend, then use that. If the setting is empty and the default Celery Result Backend is Memcache or Redis, then use that Otherwise fail """ jobtastic_cache_setting = app.conf.get('JOBTASTIC_CACHE') if isinstance(jobtastic_cache_setting, BaseCache): return jobtastic_cache_setting if 'Django' in CACHES: if jobtastic_cache_setting: try: return WrappedCache(get_django_cache(jobtastic_cache_setting)) except InvalidCacheBackendError: pass else: return WrappedCache(get_django_cache('default')) if 'Werkzeug' in CACHES: if jobtastic_cache_setting: backend, url = get_backend_by_url(jobtastic_cache_setting) backend = backend(app=app, url=url) else: backend = app.backend if isinstance(backend, CacheBackend): return WrappedCache(MemcachedCache(backend.client)) elif isinstance(backend, RedisBackend): return WrappedCache(RedisCache(backend.client)) # Give up raise RuntimeError('Cannot find a suitable cache for Jobtastic')
def get_cache(app): """ Attempt to find a valid cache from the Celery configuration If the setting is a valid cache, just use it. Otherwise, if Django is installed, then: If the setting is a valid Django cache entry, then use that. If the setting is empty use the default cache Otherwise, if Werkzeug is installed, then: If the setting is a valid Celery Memcache or Redis Backend, then use that. If the setting is empty and the default Celery Result Backend is Memcache or Redis, then use that Otherwise fail """ jobtastic_cache_setting = app.conf.get("JOBTASTIC_CACHE") if isinstance(jobtastic_cache_setting, BaseCache): return jobtastic_cache_setting if "Django" in CACHES: if jobtastic_cache_setting: try: return WrappedCache(get_django_cache(jobtastic_cache_setting)) except InvalidCacheBackendError: pass else: return WrappedCache(get_django_cache("default")) if "Werkzeug" in CACHES: if jobtastic_cache_setting: backend, url = get_backend_by_url(jobtastic_cache_setting) backend = backend(app=app, url=url) else: backend = app.backend if isinstance(backend, CacheBackend): return WrappedCache(MemcachedCache(backend.client)) elif isinstance(backend, RedisBackend): return WrappedCache(RedisCache(backend.client)) # Give up raise RuntimeError("Cannot find a suitable cache for Jobtastic")
def clear_all_caches(): for cache in settings.CACHES: clear_cache(get_django_cache(cache))
def get_cache(): cache_name = cachalot_settings.CACHALOT_CACHE nested_caches = NESTED_CACHES[cache_name] if nested_caches: return nested_caches[-1] return get_django_cache(cache_name)
def get_cache(): return get_django_cache(JAQ_CACHE)