Python django.core.cache.DEFAULT_CACHE_ALIAS Examples
The following are 7
code examples of django.core.cache.DEFAULT_CACHE_ALIAS().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.core.cache
, or try the search function
.
Example #1
Source File: settings.py From django-cachalot with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #2
Source File: api.py From django-cachalot with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #3
Source File: api.py From django-cachalot with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): self.db_alias2 = next(alias for alias in settings.DATABASES if alias != DEFAULT_DB_ALIAS) self.cache_alias2 = next(alias for alias in settings.CACHES if alias != DEFAULT_CACHE_ALIAS) self.t1 = Test.objects.create(name='test1') self.t2 = Test.objects.using(self.db_alias2).create(name='test2') self.u = User.objects.create_user('test')
Example #4
Source File: jinja2ext.py From django-cachalot with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #5
Source File: api.py From django-perf-rec with MIT License | 5 votes |
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})
Example #6
Source File: tests_basic.py From easy_cache with MIT License | 5 votes |
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)
Example #7
Source File: api.py From django-cachalot with BSD 3-Clause "New" or "Revised" License | 4 votes |
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!')