当前位置: 首页>>代码示例>>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;未经允许,请勿转载。