本文整理汇总了Python中django.core.cache.cache.clear方法的典型用法代码示例。如果您正苦于以下问题:Python cache.clear方法的具体用法?Python cache.clear怎么用?Python cache.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.cache.cache
的用法示例。
在下文中一共展示了cache.clear方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_live_rules_with_caching
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import clear [as 别名]
def test_live_rules_with_caching(self):
settings.RULESET_CACHE_TIMEOUT = 10
self.assertIsNone(cache.get(settings.RULESET_CACHE_KEY))
# save a couple of rules
RuleSet.objects.create(uri_regex="", enabled=True)
RuleSet.objects.create(uri_regex="", enabled=True)
self.assertEqual(RuleSet.objects.live_rules().count(), 2)
self.assertIsNotNone(cache.get(settings.RULESET_CACHE_KEY))
# cache is full, delete the underlying records and retrieve
RuleSet.objects.all().delete()
# we're going to the cache, so even so DB is empty, we get two back
self.assertEqual(RuleSet.objects.live_rules().count(), 2)
# clear out cache and confirm we're now going direct to DB
cache.clear()
self.assertEqual(RuleSet.objects.live_rules().count(), 0)
示例2: setUp
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import clear [as 别名]
def setUp(self):
cache.clear()
示例3: setUp
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import clear [as 别名]
def setUp(self):
cache.clear()
self._create_operator()
示例4: setUp
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import clear [as 别名]
def setUp(self):
cache.clear()
self.factory = RequestFactory()
self.operator = self._create_operator()
示例5: tearDown
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import clear [as 别名]
def tearDown(self):
# make sure every test has a clean slate for k8s mocking
cache.clear()
示例6: tearDown
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import clear [as 别名]
def tearDown(self):
# Restore default tags to empty string
settings.DEIS_DEFAULT_CONFIG_TAGS = ''
# make sure every test has a clean slate for k8s mocking
cache.clear()
示例7: clear_cache
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import clear [as 别名]
def clear_cache(self):
cache.clear()
示例8: setUp
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import clear [as 别名]
def setUp(self):
cache.clear()
Play.objects.bulk_create([
Play(title='Romeo And Juliet',
genre='Tragedy',
year=1597,
author=Author.objects.create(name='Play Shakespeare 1')),
Play(title="A Midsummer Night's Dream",
genre='Comedy',
year=1600,
author=Author.objects.create(name='Play Shakespeare 2')),
Play(title='Julius Caesar',
genre='Tragedy',
year=1623,
author=Author.objects.create(name='Play Shakespeare 3')),
Play(title='As You Like It',
genre='Comedy',
year=1623,
author=Author.objects.create(name='Play Shakespeare 4'))
])
Poem.objects.bulk_create([
Poem(title="Shall I compare thee to a summer's day?",
style="Sonnet",
author=Author.objects.create(name='Poem Shakespeare 1')),
Poem(title="As a decrepit father takes delight",
style="Sonnet",
author=Author.objects.create(name='Poem Shakespeare 2')),
Poem(title="A Lover's Complaint",
style="Narrative",
author=Author.objects.create(name='Poem Shakespeare 3'))
])
示例9: handle
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import clear [as 别名]
def handle(self, *args, **options):
if options["operation"] == "graphs":
self.cache_graphs()
if options["operation"] == "verify_cache":
self.verify_cache()
if options["operation"] == "clear":
self.clear()
示例10: clear
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import clear [as 别名]
def clear(self):
cache.clear()
示例11: test_middleware_new_participant
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import clear [as 别名]
def test_middleware_new_participant(self):
""" This test ensures the middleware creates the Participant corresponding to request.user, if not done yet. """
# we ensure the cache is empty
cache.clear()
# we have no participant yet
self.assertRaises(ObjectDoesNotExist, Participant.objects.get, id=self.request.user.id)
with self.assertNumQueries(2):
self.middleware.process_view(request=self.request, callback=None, callback_args=None, callback_kwargs=None)
# the user has been created
self.assertTrue(Participant.objects.get(id=self.request.user.id))
self.assertEqual(self.request.rest_messaging_participant.id, self.request.user.id)
# we rehit the middleware, rest_messaging_participant has been cached
with self.assertNumQueries(0):
self.middleware.process_view(request=self.request, callback=None, callback_args=None, callback_kwargs=None)
示例12: test_middleware_existing_participant
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import clear [as 别名]
def test_middleware_existing_participant(self):
""" This test ensures the middleware creates the Participant corresponding to request.user, if not done yet. """
# we ensure the cache is empty
cache.clear()
# we have a participant
Participant.objects.create(id=self.request.user.id)
with self.assertNumQueries(1):
self.middleware.process_view(request=self.request, callback=None, callback_args=None, callback_kwargs=None)
self.assertEqual(self.request.rest_messaging_participant.id, self.request.user.id)
# we rehit the middleware, rest_messaging_participant has been cached
with self.assertNumQueries(0):
self.middleware.process_view(request=self.request, callback=None, callback_args=None, callback_kwargs=None)
示例13: _test_requests_are_throttled
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import clear [as 别名]
def _test_requests_are_throttled(self, rates, counts):
cache.clear()
request = self.factory.get('/')
with override_rates(rates):
view = MockView.as_view()
sum_delay = 0
for delay, count in counts:
sum_delay += delay
with mock.patch('desecapi.throttling.ScopedRatesThrottle.timer', return_value=time.time() + sum_delay):
for _ in range(count):
response = view(request)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response = view(request)
self.assertEqual(response.status_code, status.HTTP_429_TOO_MANY_REQUESTS)