本文整理汇总了Python中django.core.cache.backends.base.InvalidCacheBackendError方法的典型用法代码示例。如果您正苦于以下问题:Python base.InvalidCacheBackendError方法的具体用法?Python base.InvalidCacheBackendError怎么用?Python base.InvalidCacheBackendError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.cache.backends.base
的用法示例。
在下文中一共展示了base.InvalidCacheBackendError方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_redis_connection
# 需要导入模块: from django.core.cache.backends import base [as 别名]
# 或者: from django.core.cache.backends.base import InvalidCacheBackendError [as 别名]
def get_redis_connection():
""" Get the redis connection if not using mock """
if config.MOCK_REDIS: # pragma: no cover
import mockredis
return mockredis.mock_strict_redis_client() # pragma: no cover
elif config.DEFENDER_REDIS_NAME: # pragma: no cover
try:
cache = caches[config.DEFENDER_REDIS_NAME]
except InvalidCacheBackendError:
raise KeyError(INVALID_CACHE_ERROR_MSG.format(config.DEFENDER_REDIS_NAME))
# every redis backend implement it own way to get the low level client
try:
# redis_cache.RedisCache case (django-redis-cache package)
return cache.get_master_client()
except AttributeError:
# django_redis.cache.RedisCache case (django-redis package)
return cache.client.get_client(True)
else: # pragma: no cover
redis_config = parse_redis_url(
config.DEFENDER_REDIS_URL, config.DEFENDER_REDIS_PASSWORD_QUOTE)
return redis.StrictRedis(
host=redis_config.get("HOST"),
port=redis_config.get("PORT"),
db=redis_config.get("DB"),
password=redis_config.get("PASSWORD"),
ssl=redis_config.get("SSL"),
)
示例2: get_cache
# 需要导入模块: from django.core.cache.backends import base [as 别名]
# 或者: from django.core.cache.backends.base import InvalidCacheBackendError [as 别名]
def get_cache(cache=None):
"""Return ``cache`` or the 'default' cache if ``cache`` is not specified or
``cache`` is not configured.
:param cache: The name of the requested cache.
"""
try:
# Check for proper Redis persistent backends
# FIXME: this logic needs to be a system sanity check
if (
not settings.DEBUG
and cache in PERSISTENT_STORES
and (
cache not in settings.CACHES
or "RedisCache" not in settings.CACHES[cache]["BACKEND"]
or settings.CACHES[cache].get("TIMEOUT", "") is not None
)
):
raise ImproperlyConfigured(
"Pootle requires a Redis-backed caching backend for %r "
"with `TIMEOUT: None`. Please review your settings." % cache
)
return caches[cache]
except InvalidCacheBackendError:
return default_cache
示例3: __init__
# 需要导入模块: from django.core.cache.backends import base [as 别名]
# 或者: from django.core.cache.backends.base import InvalidCacheBackendError [as 别名]
def __init__(self, server, params):
import warnings
warnings.warn(
"memcached.CacheClass has been split into memcached.MemcachedCache and memcached.PyLibMCCache. Please update your cache backend setting.",
DeprecationWarning
)
try:
import memcache
except ImportError:
raise InvalidCacheBackendError(
"Memcached cache backend requires either the 'memcache' or 'cmemcache' library"
)
super(CacheClass, self).__init__(server, params,
library=memcache,
value_not_found_exception=ValueError)
示例4: test_non_default_cache
# 需要导入模块: from django.core.cache.backends import base [as 别名]
# 或者: from django.core.cache.backends.base import InvalidCacheBackendError [as 别名]
def test_non_default_cache(self):
# 21000 - CacheDB backend should respect SESSION_CACHE_ALIAS.
with self.assertRaises(InvalidCacheBackendError):
self.backend()
示例5: get_cache_backend
# 需要导入模块: from django.core.cache.backends import base [as 别名]
# 或者: from django.core.cache.backends.base import InvalidCacheBackendError [as 别名]
def get_cache_backend():
if hasattr(settings, 'CACHES'):
if "django_mail_admin" in settings.CACHES:
return get_cache("django_mail_admin")
else:
# Sometimes this raises InvalidCacheBackendError, which is ok too
try:
return get_cache("default")
except InvalidCacheBackendError:
pass
return None