當前位置: 首頁>>代碼示例>>Python>>正文


Python base.InvalidCacheBackendError方法代碼示例

本文整理匯總了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"),
        ) 
開發者ID:jazzband,項目名稱:django-defender,代碼行數:30,代碼來源:connection.py

示例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 
開發者ID:evernote,項目名稱:zing,代碼行數:28,代碼來源:cache.py

示例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) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:17,代碼來源:memcached.py

示例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() 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:tests.py

示例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 
開發者ID:Bearle,項目名稱:django_mail_admin,代碼行數:13,代碼來源:settings.py


注:本文中的django.core.cache.backends.base.InvalidCacheBackendError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。