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


Python cache.clear方法代碼示例

本文整理匯總了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) 
開發者ID:yunojuno,項目名稱:django-request-profiler,代碼行數:18,代碼來源:test_models.py

示例2: setUp

# 需要導入模塊: from django.core.cache import cache [as 別名]
# 或者: from django.core.cache.cache import clear [as 別名]
def setUp(self):
        cache.clear() 
開發者ID:openwisp,項目名稱:openwisp-users,代碼行數:4,代碼來源:test_views.py

示例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() 
開發者ID:openwisp,項目名稱:openwisp-users,代碼行數:5,代碼來源:test_throttling.py

示例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() 
開發者ID:openwisp,項目名稱:openwisp-users,代碼行數:6,代碼來源:test_authentication.py

示例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() 
開發者ID:deis,項目名稱:controller,代碼行數:5,代碼來源:test_tags.py

示例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() 
開發者ID:deis,項目名稱:controller,代碼行數:7,代碼來源:test_config.py

示例7: clear_cache

# 需要導入模塊: from django.core.cache import cache [as 別名]
# 或者: from django.core.cache.cache import clear [as 別名]
def clear_cache(self):
        cache.clear() 
開發者ID:mozilla,項目名稱:normandy,代碼行數:4,代碼來源:test_authentication.py

示例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'))
        ]) 
開發者ID:MattBroach,項目名稱:DjangoRestMultipleModels,代碼行數:35,代碼來源:utils.py

示例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() 
開發者ID:archesproject,項目名稱:arches,代碼行數:11,代碼來源:cache.py

示例10: clear

# 需要導入模塊: from django.core.cache import cache [as 別名]
# 或者: from django.core.cache.cache import clear [as 別名]
def clear(self):
        cache.clear() 
開發者ID:archesproject,項目名稱:arches,代碼行數:4,代碼來源:cache.py

示例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) 
開發者ID:raphaelgyory,項目名稱:django-rest-messaging,代碼行數:16,代碼來源:test_middleware.py

示例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) 
開發者ID:raphaelgyory,項目名稱:django-rest-messaging,代碼行數:14,代碼來源:test_middleware.py

示例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) 
開發者ID:desec-io,項目名稱:desec-stack,代碼行數:17,代碼來源:test_throttling.py


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