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


Python cache.InvalidCacheBackendError方法代碼示例

本文整理匯總了Python中django.core.cache.InvalidCacheBackendError方法的典型用法代碼示例。如果您正苦於以下問題:Python cache.InvalidCacheBackendError方法的具體用法?Python cache.InvalidCacheBackendError怎麽用?Python cache.InvalidCacheBackendError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.core.cache的用法示例。


在下文中一共展示了cache.InvalidCacheBackendError方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: handle

# 需要導入模塊: from django.core import cache [as 別名]
# 或者: from django.core.cache import InvalidCacheBackendError [as 別名]
def handle(self, *args, **options):
        verbosity = options.get("verbosity")

        aliases = set(options["aliases"])

        if not aliases:
            aliases = settings.CACHES

        for alias in aliases:
            try:
                cache = caches[alias]
            except InvalidCacheBackendError:
                raise CommandError("Cache '{}' does not exist".format(alias))

            if not isinstance(cache, MySQLCache):  # pragma: no cover
                continue

            if verbosity >= 1:
                self.stdout.write(
                    "Deleting from cache '{}'... ".format(alias), ending=""
                )
            num_deleted = cache.cull()
            if verbosity >= 1:
                self.stdout.write("{} entries deleted.".format(num_deleted)) 
開發者ID:adamchainz,項目名稱:django-mysql,代碼行數:26,代碼來源:cull_mysql_caches.py

示例2: handle

# 需要導入模塊: from django.core import cache [as 別名]
# 或者: from django.core.cache import InvalidCacheBackendError [as 別名]
def handle(self, *args, **options):
        aliases = set(options["aliases"])

        if not aliases:
            aliases = settings.CACHES

        tables = set()
        for alias in aliases:
            try:
                cache = caches[alias]
            except InvalidCacheBackendError:
                raise CommandError("Cache '{}' does not exist".format(alias))

            if not isinstance(cache, MySQLCache):  # pragma: no cover
                continue

            tables.add(cache._table)

        if not tables:
            self.stderr.write("No MySQLCache instances in CACHES")
            return

        migration = self.render_migration(tables)
        self.stdout.write(migration) 
開發者ID:adamchainz,項目名稱:django-mysql,代碼行數:26,代碼來源:mysql_cache_migration.py

示例3: render

# 需要導入模塊: from django.core import cache [as 別名]
# 或者: from django.core.cache import InvalidCacheBackendError [as 別名]
def render(self, context):
        try:
            expire_time = self.expire_time_var.resolve(context)
        except VariableDoesNotExist:
            raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.expire_time_var.var)
        try:
            expire_time = int(expire_time)
        except (ValueError, TypeError):
            raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time)
        if self.cache_name:
            try:
                cache_name = self.cache_name.resolve(context)
            except VariableDoesNotExist:
                raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.cache_name.var)
            try:
                fragment_cache = caches[cache_name]
            except InvalidCacheBackendError:
                raise TemplateSyntaxError('Invalid cache name specified for cache tag: %r' % cache_name)
        else:
            try:
                fragment_cache = caches['template_fragments']
            except InvalidCacheBackendError:
                fragment_cache = caches['default']

        vary_on = [var.resolve(context) for var in self.vary_on]
        cache_key = make_template_fragment_key(self.fragment_name, vary_on)
        value = fragment_cache.get(cache_key)
        if value is None:
            value = self.nodelist.render(context)
            fragment_cache.set(cache_key, value, expire_time)
        return value 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:33,代碼來源:cache.py

示例4: render

# 需要導入模塊: from django.core import cache [as 別名]
# 或者: from django.core.cache import InvalidCacheBackendError [as 別名]
def render(self, context):
        try:
            expire_time = self.expire_time_var.resolve(context)
        except VariableDoesNotExist:
            raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.expire_time_var.var)
        if expire_time is not None:
            try:
                expire_time = int(expire_time)
            except (ValueError, TypeError):
                raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time)
        if self.cache_name:
            try:
                cache_name = self.cache_name.resolve(context)
            except VariableDoesNotExist:
                raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.cache_name.var)
            try:
                fragment_cache = caches[cache_name]
            except InvalidCacheBackendError:
                raise TemplateSyntaxError('Invalid cache name specified for cache tag: %r' % cache_name)
        else:
            try:
                fragment_cache = caches['template_fragments']
            except InvalidCacheBackendError:
                fragment_cache = caches['default']

        vary_on = [var.resolve(context) for var in self.vary_on]
        cache_key = make_template_fragment_key(self.fragment_name, vary_on)
        value = fragment_cache.get(cache_key)
        if value is None:
            value = self.nodelist.render(context)
            fragment_cache.set(cache_key, value, expire_time)
        return value 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:34,代碼來源:cache.py

示例5: get_cache

# 需要導入模塊: from django.core import cache [as 別名]
# 或者: from django.core.cache import InvalidCacheBackendError [as 別名]
def get_cache():
        """
        Gets the current cache provider
        :return: a cache provider
        """
        try:
            return caches[Conf.CACHE]
        except InvalidCacheBackendError:
            return None 
開發者ID:Koed00,項目名稱:django-q,代碼行數:11,代碼來源:__init__.py

示例6: test_non_default_cache

# 需要導入模塊: from django.core import cache [as 別名]
# 或者: from django.core.cache import InvalidCacheBackendError [as 別名]
def test_non_default_cache(self):
        # 21000 - CacheDB backend should respect SESSION_CACHE_ALIAS.
        with self.assertRaises(InvalidCacheBackendError):
            self.backend() 
開發者ID:r4fek,項目名稱:django-cassandra-engine,代碼行數:6,代碼來源:test_sessions.py

示例7: throttling_cache

# 需要導入模塊: from django.core import cache [as 別名]
# 或者: from django.core.cache import InvalidCacheBackendError [as 別名]
def throttling_cache():
    """
    Returns the cache specifically used for throttling.
    """
    try:
        return caches['throttling']
    except InvalidCacheBackendError:
        return caches['default'] 
開發者ID:edx,項目名稱:course-discovery,代碼行數:10,代碼來源:throttles.py

示例8: purge_from_cache

# 需要導入模塊: from django.core import cache [as 別名]
# 或者: from django.core.cache import InvalidCacheBackendError [as 別名]
def purge_from_cache(self):
        try:
            cache = caches['renditions']
            cache.delete(self.construct_cache_key(
                self.image_id, self.focal_point_key, self.filter_spec
            ))
        except InvalidCacheBackendError:
            pass 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:10,代碼來源:models.py

示例9: __init__

# 需要導入模塊: from django.core import cache [as 別名]
# 或者: from django.core.cache import InvalidCacheBackendError [as 別名]
def __init__(self, server, params):
        self.update_params(params)
        super(ElastiCache, self).__init__(server, params)
        if len(self._servers) > 1:
            raise InvalidCacheBackendError(
                'ElastiCache should be configured with only one server '
                '(Configuration Endpoint)')
        if len(self._servers[0].split(':')) != 2:
            raise InvalidCacheBackendError(
                'Server configuration should be in format IP:port')

        self._ignore_cluster_errors = self._options.get(
            'IGNORE_CLUSTER_ERRORS', False) 
開發者ID:gusdan,項目名稱:django-elasticache,代碼行數:15,代碼來源:memcached.py

示例10: get_rendition

# 需要導入模塊: from django.core import cache [as 別名]
# 或者: from django.core.cache import InvalidCacheBackendError [as 別名]
def get_rendition(self, filter):
        if isinstance(filter, str):
            filter = Filter(spec=filter)

        cache_key = filter.get_cache_key(self)
        Rendition = self.get_rendition_model()

        try:
            rendition_caching = True
            cache = caches['renditions']
            rendition_cache_key = Rendition.construct_cache_key(
                self.id,
                cache_key,
                filter.spec
            )
            cached_rendition = cache.get(rendition_cache_key)
            if cached_rendition:
                return cached_rendition
        except InvalidCacheBackendError:
            rendition_caching = False

        try:
            rendition = self.renditions.get(
                filter_spec=filter.spec,
                focal_point_key=cache_key,
            )
        except Rendition.DoesNotExist:
            # Generate the rendition image
            generated_image = filter.run(self, BytesIO())

            # Generate filename
            input_filename = os.path.basename(self.file.name)
            input_filename_without_extension, input_extension = os.path.splitext(input_filename)

            # A mapping of image formats to extensions
            FORMAT_EXTENSIONS = {
                'jpeg': '.jpg',
                'png': '.png',
                'gif': '.gif',
                'webp': '.webp',
            }

            output_extension = filter.spec.replace('|', '.') + FORMAT_EXTENSIONS[generated_image.format_name]
            if cache_key:
                output_extension = cache_key + '.' + output_extension

            # Truncate filename to prevent it going over 60 chars
            output_filename_without_extension = input_filename_without_extension[:(59 - len(output_extension))]
            output_filename = output_filename_without_extension + '.' + output_extension

            rendition, created = self.renditions.get_or_create(
                filter_spec=filter.spec,
                focal_point_key=cache_key,
                defaults={'file': File(generated_image.f, name=output_filename)}
            )

        if rendition_caching:
            cache.set(rendition_cache_key, rendition)

        return rendition 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:62,代碼來源:models.py


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