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