当前位置: 首页>>代码示例>>Python>>正文


Python cache.DEFAULT_CACHE_ALIAS属性代码示例

本文整理汇总了Python中django.core.cache.DEFAULT_CACHE_ALIAS属性的典型用法代码示例。如果您正苦于以下问题:Python cache.DEFAULT_CACHE_ALIAS属性的具体用法?Python cache.DEFAULT_CACHE_ALIAS怎么用?Python cache.DEFAULT_CACHE_ALIAS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在django.core.cache的用法示例。


在下文中一共展示了cache.DEFAULT_CACHE_ALIAS属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cache

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import DEFAULT_CACHE_ALIAS [as 别名]
def test_cache(self):
        other_cache_alias = next(alias for alias in settings.CACHES
                                 if alias != DEFAULT_CACHE_ALIAS)
        invalidate(Test, cache_alias=other_cache_alias)

        qs = Test.objects.all()

        with self.settings(CACHALOT_CACHE=DEFAULT_CACHE_ALIAS):
            self.assert_query_cached(qs)

        with self.settings(CACHALOT_CACHE=other_cache_alias):
            self.assert_query_cached(qs)

        Test.objects.create(name='test')

        # Only `CACHALOT_CACHE` is invalidated, so changing the database should
        # not invalidate all caches.
        with self.settings(CACHALOT_CACHE=other_cache_alias):
            self.assert_query_cached(qs, before=0) 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:21,代码来源:settings.py

示例2: setUp

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import DEFAULT_CACHE_ALIAS [as 别名]
def setUp(self):
        super(APITestCase, self).setUp()
        self.t1 = Test.objects.create(name='test1')
        self.cache_alias2 = next(alias for alias in settings.CACHES
                                 if alias != DEFAULT_CACHE_ALIAS) 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:7,代码来源:api.py

示例3: cache

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import DEFAULT_CACHE_ALIAS [as 别名]
def cache(self, *args, **kwargs):
        cache_alias = kwargs.get('cache_alias', DEFAULT_CACHE_ALIAS)
        cache_key = kwargs.get('cache_key', kwargs['default_cache_key'])
        if cache_key is None:
            raise ValueError(
                'You must set `cache_key` when the template is not a file.')
        cache_key = make_template_fragment_key(cache_key, args)

        out = caches[cache_alias].get(cache_key)
        if out is None:
            out = kwargs['caller']()
            caches[cache_alias].set(cache_key, out, kwargs.get('timeout'))
        return out 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:15,代码来源:jinja2ext.py

示例4: on_cache_op

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import DEFAULT_CACHE_ALIAS [as 别名]
def on_cache_op(self, cache_op):
        name_parts = ["cache"]
        if cache_op.alias != DEFAULT_CACHE_ALIAS:
            name_parts.append(cache_op.alias)
        name_parts.append(cache_op.operation)
        name = "|".join(name_parts)

        self.record.append({name: cache_op.key_or_keys}) 
开发者ID:adamchainz,项目名称:django-perf-rec,代码行数:10,代码来源:api.py

示例5: __repr__

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import DEFAULT_CACHE_ALIAS [as 别名]
def __repr__(self):
        name = type(self._cache)
        try:
            from django.core.cache import DEFAULT_CACHE_ALIAS, caches, DefaultCacheProxy
            if isinstance(self._cache, DefaultCacheProxy):
                name = type(caches[DEFAULT_CACHE_ALIAS])
        except Exception:
            pass
        return 'ThreadLocalCache {}'.format(name) 
开发者ID:Bahus,项目名称:easy_cache,代码行数:11,代码来源:tests_basic.py

示例6: test_cache_jinja2

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import DEFAULT_CACHE_ALIAS [as 别名]
def test_cache_jinja2(self):
        # Invalid arguments
        with self.assertRaises(TemplateSyntaxError,
                               msg="'invalid' is not a valid keyword argument "
                                   "for {% cache %}"):
            engines['jinja2'].from_string("""
            {% cache cache_key='anything', invalid='what?' %}{% endcache %}
            """)
        with self.assertRaises(ValueError, msg='You must set `cache_key` when '
                                               'the template is not a file.'):
            engines['jinja2'].from_string(
                '{% cache %} broken {% endcache %}').render()

        # With the minimum number of arguments
        template = engines['jinja2'].from_string("""
        {%- cache cache_key='first' -%}
            {{ content1 }}
        {%- endcache -%}
        {%- cache cache_key='second' -%}
            {{ content2 }}
        {%- endcache -%}
        """)
        content = template.render({'content1': 'abc', 'content2': 'def'})
        self.assertEqual(content, 'abcdef')
        invalidate()
        content = template.render({'content1': 'ghi', 'content2': 'jkl'})
        self.assertEqual(content, 'abcdef')

        # With the maximum number of arguments
        template = engines['jinja2'].from_string("""
        {%- cache get_last_invalidation('auth.Group', 'cachalot_test',
                                        cache_alias=cache),
                 timeout=10, cache_key='cache_key_name', cache_alias=cache -%}
            {{ content }}
        {%- endcache -%}
        """)
        content = template.render({'content': 'something',
                                   'cache': self.cache_alias2})
        self.assertEqual(content, 'something')
        content = template.render({'content': 'anything',
                                   'cache': self.cache_alias2})
        self.assertEqual(content, 'something')
        invalidate('cachalot_test', cache_alias=DEFAULT_CACHE_ALIAS)
        content = template.render({'content': 'yet another',
                                   'cache': self.cache_alias2})
        self.assertEqual(content, 'something')
        invalidate('cachalot_test')
        content = template.render({'content': 'will you change?',
                                   'cache': self.cache_alias2})
        self.assertEqual(content, 'will you change?')
        caches[self.cache_alias2].clear()
        content = template.render({'content': 'better!',
                                   'cache': self.cache_alias2})
        self.assertEqual(content, 'better!') 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:56,代码来源:api.py


注:本文中的django.core.cache.DEFAULT_CACHE_ALIAS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。