Python django.core.cache.cache 模块,clear() 实例源码

我们从Python开源项目中,提取了以下37个代码示例,用于说明如何使用django.core.cache.cache.clear()

项目:jarbas    作者:datasciencebr    | 项目源码 | 文件源码
def test_contents(self):
        expected = [
            dict(subquota_description='Another subquota', subquota_id=42),
            dict(subquota_description='Subquota description', subquota_id=4)
        ]

        cache.clear()
        secondary_data = sample_reimbursement_data.copy()
        secondary_data['document_id'] = 13
        secondary_data['year'] = 1971
        secondary_data['subquota_id'] = 42
        secondary_data['subquota_description'] = 'Another subquota'
        Reimbursement.objects.create(**secondary_data)
        resp = self.client.get(self.url)

        content = loads(resp.content.decode('utf-8'))
        self.assertEqual(2, content['count'])
        self.assertEqual(expected, content['results'])
项目:jarbas    作者:datasciencebr    | 项目源码 | 文件源码
def test_contents(self):
        expected = [
            dict(congressperson_name='John Doe', applicant_id=42),
            dict(congressperson_name='Roger That', applicant_id=13)
        ]

        cache.clear()
        secondary_data = sample_reimbursement_data.copy()
        secondary_data['applicant_id'] = 42
        secondary_data['congressperson_name'] = 'John Doe'
        secondary_data['document_id'] = 13
        Reimbursement.objects.create(**secondary_data)
        resp = self.client.get(self.url)

        content = loads(resp.content.decode('utf-8'))
        self.assertEqual(2, content['count'])
        self.assertEqual(expected, content['results'])
项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def test_show_placeholder_lang_parameter(self):
        from django.core.cache import cache

        cache.clear()
        page = create_page('Test', 'col_two.html', 'en')
        create_title('fr', 'Fr Test', page)
        placeholder = page.placeholders.all()[0]
        add_plugin(placeholder, TextPlugin, 'en', body='<b>En Test</b>')
        add_plugin(placeholder, TextPlugin, 'fr', body='<b>Fr Test</b>')
        request = RequestFactory().get('/')
        request.user = AnonymousUser()
        request.current_page = page
        template = "{% load cms_tags sekizai_tags %}{% show_placeholder slot page 'en' 1 %}{% render_block 'js' %}"
        output = self.render_template_obj(template, {'page': page, 'slot': placeholder.slot}, request)
        self.assertIn('<b>En Test</b>', output)

        template = "{% load cms_tags sekizai_tags %}{% show_placeholder slot page 'fr' 1 %}{% render_block 'js' %}"
        output = self.render_template_obj(template, {'page': page, 'slot': placeholder.slot}, request)
        self.assertIn('<b>Fr Test</b>', output)
项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def test_show_placeholder_for_page_marks_output_safe(self):
        from django.core.cache import cache

        cache.clear()
        page = create_page('Test', 'col_two.html', 'en')
        placeholder = page.placeholders.all()[0]
        add_plugin(placeholder, TextPlugin, 'en', body='<b>Test</b>')
        request = RequestFactory().get('/')
        request.user = AnonymousUser()
        request.current_page = page
        template = "{% load cms_tags sekizai_tags %}{% show_placeholder slot page 'en' 1 %}{% render_block 'js' %}"
        with self.assertNumQueries(4):
            output = self.render_template_obj(template, {'page': page, 'slot': placeholder.slot}, request)
        self.assertIn('<b>Test</b>', output)

        with self.assertNumQueries(0):
            output = self.render_template_obj(template, {'page': page, 'slot': placeholder.slot}, request)
        self.assertIn('<b>Test</b>', output)
项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def test_cached_show_placeholder_preview(self):
        from django.core.cache import cache
        cache.clear()
        page = create_page('Test', 'col_two.html', 'en', published=True)
        placeholder = page.placeholders.all()[0]
        add_plugin(placeholder, TextPlugin, 'en', body='<b>Test</b>')
        request = RequestFactory().get('/')
        user = self._create_user("admin", True, True)
        request.current_page = page.publisher_public
        request.user = user
        template = "{% load cms_tags %}{% show_placeholder slot page 'en' 1 %}"
        with self.assertNumQueries(4):
            output = self.render_template_obj(template, {'page': page, 'slot': placeholder.slot}, request)
        self.assertIn('<b>Test</b>', output)
        add_plugin(placeholder, TextPlugin, 'en', body='<b>Test2</b>')
        request = RequestFactory().get('/?preview')
        request.current_page = page
        request.user = user
        with self.assertNumQueries(4):
            output = self.render_template_obj(template, {'page': page, 'slot': placeholder.slot}, request)
        self.assertIn('<b>Test2</b>', output)
项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def test_render_plugin(self):
        from django.core.cache import cache
        cache.clear()
        page = create_page('Test', 'col_two.html', 'en', published=True)
        placeholder = page.placeholders.all()[0]
        plugin = add_plugin(placeholder, TextPlugin, 'en', body='<b>Test</b>')
        template = "{% load cms_tags %}{% render_plugin plugin %}"
        request = RequestFactory().get('/')
        user = self._create_user("admin", True, True)
        request.user = user
        request.current_page = page
        request.session = {}
        request.toolbar = CMSToolbar(request)
        with self.assertNumQueries(0):
            output = self.render_template_obj(template, {'plugin': plugin}, request)
        self.assertIn('<b>Test</b>', output)
项目:SensDB3    作者:aapris    | 项目源码 | 文件源码
def test_datalogger_list(self):
        url = reverse("v2:datalogger-list")
        user = mommy.make("User")
        another_user = mommy.make("User")

        self.client.force_authenticate(user=user)
        mommy.make_recipe("data.active_datalogger", user=user)
        self.assertEqual(len(self._get_results(url)), 1)

        # should be cached
        mommy.make_recipe("data.active_datalogger", user=user)
        self.assertEqual(len(self._get_results(url)), 1)

        cache.clear()
        self.assertEqual(len(self._get_results(url)), 2)

        # the other user should not see cached results
        self.client.force_authenticate(user=another_user)
        self.assertEqual(len(self._get_results(url)), 0)
项目:utaustin-django-example    作者:singingwolfboy    | 项目源码 | 文件源码
def test_cached_home_page(client):
    response1 = client.get("/")
    assert response1.status_code == 200
    # insert a tweet into the database
    user = User(username="bob_ross")
    user.save()
    tweet = Tweet(content="happy little trees", creator=user)
    tweet.save()
    # check the homepage again -- it should *not* be updated,
    # due to the cache
    response2 = client.get("/")
    assert response2.status_code == 200
    assert "happy little trees" not in response2.content
    # flush the cache, and the tweet should appear!
    cache.clear()
    response3 = client.get("/")
    assert response3.status_code == 200
    assert "happy little trees" in response3.content
项目:updater    作者:mmohrhard    | 项目源码 | 文件源码
def partial_targets(request, api_version, channel, os):
    if int(api_version) != 1:
        return JsonResponse({'error' : 'only api version 1 supported right now'})

    update_channel = get_object_or_404(UpdateChannel, name = channel)
    matched_releases = Release.objects.filter(os = os, channel = update_channel).order_by('-added')
    data = {'updates':[]}
    print(matched_releases.count())
    print(os)
    print(channel)
    num_updates = update_channel.num_partial_updates
    for release in matched_releases[:num_updates]:
        language_objects = LanguageFile.objects.filter(release = release)
        languages = {}
        for language_object in language_objects:
            languages[language_object.language] = get_update_file(language_object.mar_file)
        partial = {'update': get_update_file(release.release_file),
                'build': release.name,
                'languages': languages}

        data['updates'].append(partial)
    cache.clear()
    return JsonResponse(data)
项目:django-lrucache-backend    作者:kogan    | 项目源码 | 文件源码
def tearDown(self):
        self.cache.clear()
项目:django-lrucache-backend    作者:kogan    | 项目源码 | 文件源码
def test_clear(self):
        # The cache can be emptied using clear
        cache = self.cache
        cache.set("key1", "spam")
        cache.set("key2", "eggs")
        cache.clear()
        self.assertIsNone(cache.get("key1"))
        self.assertIsNone(cache.get("key2"))
项目:jarbas    作者:datasciencebr    | 项目源码 | 文件源码
def test_template(self):
        cache.clear()
        resp = self.client.get(resolve_url('home'))
        self.assertTemplateUsed(resp, 'frontend/home.html')
项目:jarbas    作者:datasciencebr    | 项目源码 | 文件源码
def test_google_api_key(self):
        cache.clear()
        resp = self.client.get(resolve_url('home'))
        expected = "googleStreetViewApiKey: '42'"
        self.assertIn(expected, resp.content.decode('utf-8'))
项目:django-redis-sentinel-redux    作者:danigosa    | 项目源码 | 文件源码
def setUp(self):
        self.old_kf = settings.CACHES['default'].get('KEY_FUNCTION')
        self.old_rkf = settings.CACHES['default'].get('REVERSE_KEY_FUNCTION')
        settings.CACHES['default']['KEY_FUNCTION'] = 'redis_backend_testapp.tests.make_key'
        settings.CACHES['default']['REVERSE_KEY_FUNCTION'] = 'redis_backend_testapp.tests.reverse_key'

        self.cache = caches['default']
        try:
            self.cache.clear()
        except Exception:
            pass
项目:django-redis-sentinel-redux    作者:danigosa    | 项目源码 | 文件源码
def setUp(self):
        self.cache = cache

        try:
            self.cache.clear()
        except Exception:
            pass
项目:django-redis-sentinel-redux    作者:danigosa    | 项目源码 | 文件源码
def test_clear_with_cache_prefix(self):
        """
        Tests that cache.clear() does only delete keys which starts with the
        correct prefix configured with KEY_PREFIX.
        """
        cache_normal = caches['sample']
        cache_with_prefix = caches['with_prefix']
        cache_normal.set('some_key', 'some_value')
        cache_with_prefix.set('other_key', 'other_value')

        cache_with_prefix.clear()

        self.assertIsNone(cache_with_prefix.get('other_key'))
        self.assertEqual(cache_normal.get('some_key'), 'some_value')
项目:django-redis-sentinel-redux    作者:danigosa    | 项目源码 | 文件源码
def test_clear(self):
        self.session['x'] = 1
        self.session.modified = False
        self.session.accessed = False
        self.assertEqual(list(self.session.items()), [('x', 1)])
        self.session.clear()
        self.assertEqual(list(self.session.items()), [])
        self.assertTrue(self.session.accessed)
        self.assertTrue(self.session.modified)
项目:sdining    作者:Lurance    | 项目源码 | 文件源码
def setUp(self):
        cache.clear()
项目:sdining    作者:Lurance    | 项目源码 | 文件源码
def setUp(self):
        cache.clear()
项目:django-groups-cache    作者:audiolion    | 项目源码 | 文件源码
def test_cache_invalidates_on_user_save(self):
        groups = cache_groups(self.user)
        self.assertEqual(len(groups), 1)
        self.user.set_password('new_password')
        self.user.save()
        key = generate_cache_key(self.user)
        self.assertIsNone(cache.get(key))
        cache.clear()
项目:django-groups-cache    作者:audiolion    | 项目源码 | 文件源码
def test_cache_invalidates_on_user_groups_removal(self):
        groups = cache_groups(self.user)
        self.assertEqual(len(groups), 1)
        self.user.groups.remove(self.group)
        self.user.save()
        key = generate_cache_key(self.user)
        self.assertIsNone(cache.get(key))
        cache.clear()
项目:django-groups-cache    作者:audiolion    | 项目源码 | 文件源码
def test_cache_invalidates_on_group_user_set_removal(self):
        groups = cache_groups(self.user)
        self.assertEqual(len(groups), 1)
        self.group.user_set.remove(self.user)
        self.group.save()
        self.assertEqual(len(self.group.user_set.all()), 0)
        key = generate_cache_key(self.user)
        self.assertIsNone(cache.get(key))
        cache.clear()
项目:django-groups-cache    作者:audiolion    | 项目源码 | 文件源码
def test_cache_invalidates_on_group_save(self):
        groups = cache_groups(self.user)
        self.assertEqual(len(groups), 1)
        self.group.name = 'dragonlord_ojutai'
        self.group.save()
        self.assertEqual(self.group.name, 'dragonlord_ojutai')
        key = generate_cache_key(self.user)
        self.assertIsNone(cache.get(key))
        cache.clear()
项目:django-groups-cache    作者:audiolion    | 项目源码 | 文件源码
def test_request_should_not_cache_anonymous(self):
        self.request.user = Mock()
        self.request.user.is_authenticated.return_value = False
        self.assertEqual(self.gcm.process_request(self.request), None)
        self.assertIsNone(self.request.groups_cache)
        cache.clear()
项目:django-groups-cache    作者:audiolion    | 项目源码 | 文件源码
def test_should_find_nummy_group(self):
        groups = cache_groups(self.user)
        self.assertEqual(len(groups), 1)
        self.assertIs(has_group(self.user, self.group.name), True)
        cache.clear()
        self.assertIs(has_group(self.user, self.group.name), False)
项目:django-groups-cache    作者:audiolion    | 项目源码 | 文件源码
def test_should_not_find_rocks_group(self):
        groups = cache_groups(self.user)
        self.assertEqual(len(groups), 1)
        self.assertFalse(has_group(self.user, 'rocks'))
        cache.clear()
        self.assertFalse(has_group(self.user, 'rocks'))
项目:django-eth-events    作者:gnosis    | 项目源码 | 文件源码
def tearDown(self):
        self.p.terminate()
        self.p = None
        cache.clear()
        sleep(1)
项目:isar    作者:ilbers    | 项目源码 | 文件源码
def invalidate_cache(**kwargs):
    from django.core.cache import cache
    try:
      cache.clear()
    except Exception as e:
      logger.warning("Problem with cache backend: Failed to clear cache: %s" % e)
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def setUp(self):
    cache.clear()
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def tearDown(self):
    cache.clear()
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def setUp(self):
    cache.clear()
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def setUp(self):
    ChannelSetting.objects.create(key="CAN_CREATE_PROJECTS_WITHOUT_ORGANIZATION", value="1", object_channel="default")
    cache.clear()
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def test_can_create_in_any_organization_if_settings_allow(self):
    """Test user can create project inside any organization if properly configured"""
    ChannelSetting.objects.create(key="CAN_CREATE_PROJECTS_IN_ANY_ORGANIZATION", value="1", object_channel="default")
    cache.clear()

    wrong_org = Organization(name="test", type=0, owner=self.second_user)
    wrong_org.save(object_channel="default")

    self.data['organization_id'] = wrong_org.pk
    response = self.client.post(reverse("project-list"), self.data, format="json")
    self.assertTrue(response.status_code == 201)
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def setUp(self):
    call_command('clear_index', '--noinput', verbosity=0)
    Channel.objects.create(name="Test channel", slug="test-channel")
    create_sample_projects()
    self.client = APIClient()

    cache.clear()
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def setUp(self):
    call_command('clear_index', '--noinput', verbosity=0)
    Channel.objects.create(name="Test channel", slug="test-channel")
    create_sample_organizations()
    self.client = APIClient()

    cache.clear()
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def setUp(self):
    call_command('clear_index', '--noinput', verbosity=0)
    Channel.objects.create(name="Test channel", slug="test-channel")
    create_sample_users()
    self.client = APIClient()

    ChannelSetting.objects.create(key="ENABLE_USER_SEARCH", value="1", object_channel="default")
    ChannelSetting.objects.create(key="ENABLE_USER_SEARCH", value="1", object_channel="test-channel")
    cache.clear()
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def test_user_search_must_be_enabled(self):
    """
    Test searching for users must be enabled in settings
    """
    ChannelSetting.objects.all().delete()
    cache.clear()

    response = self.client.get(reverse("search-users-list"), format="json")
    self.assertEqual(response.status_code, 403)