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

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

项目:django-lrucache-backend    作者:kogan    | 项目源码 | 文件源码
def test_delete_many(self):
        # Multiple keys can be deleted using delete_many
        cache = self.cache
        cache.set("key1", "spam")
        cache.set("key2", "eggs")
        cache.set("key3", "ham")
        cache.delete_many(["key1", "key2"])
        self.assertIsNone(cache.get("key1"))
        self.assertIsNone(cache.get("key2"))
        self.assertEqual(cache.get("key3"), "ham")
项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def _clean_many(prefix):
    from django.core.cache import cache
    keys = []
    if settings.USE_I18N:
        for lang in [language[0] for language in settings.LANGUAGES]:
            keys.append("%s-%s" %(prefix, lang))
    else:
        keys = ["%s-%s" %(prefix, settings.LANGUAGE_CODE)]
    cache.delete_many(keys)
项目:django-asyncio-redis    作者:mackeyja92    | 项目源码 | 文件源码
def test_delete_many(self):
        await self.set('test', 'test-1')
        await self.set('test2', 'test-2')
        await cache.delete_many(('test-1', 'test-2'))
        self.assertIsNone(await self.get('test-1'))
        self.assertIsNone(await self.get('test-2'))
项目:PureWhiteBlog    作者:PureWhiteWu    | 项目源码 | 文件源码
def invalidate_object_cache(cls, instance):
        # TODO: Think about raise condition
        # if new invalidation created when invalidating
        # what will happen?
        keys = cls.get_invalidation_keys_and_delete(instance)
        cache.delete_many(keys)
项目:perdiem-django    作者:RevolutionTech    | 项目源码 | 文件源码
def clear_all_profile_contexts(sender, instance, **kwargs):
    # TODO(lucas): Review to improve performance
    # Instead of clearing out all of the profile contexts, we could just clear out
    # the profile contexts associated with the investors related to this revenue report
    cache_keys = ['profile_context-{pk}'.format(pk=up.pk) for up in UserProfile.objects.all()]
    cache.delete_many(cache_keys)
项目:eoj3    作者:ultmaster    | 项目源码 | 文件源码
def invalidate_contest(contest: Contest):
    contest_users = contest.participants_ids
    cache.delete_many(list(map(lambda x: PARTICIPANT_RANK_DETAIL.format(contest=contest.pk, user=x), contest_users)))
    cache.delete_many(
        list(map(lambda x: PARTICIPANT_RANK_DETAIL_PRIVATE.format(contest=contest.pk, user=x), contest_users)))
    cache.delete(PARTICIPANT_RANK_LIST.format(contest=contest.pk))
    cache.delete(CONTEST_FIRST_YES.format(contest=contest.pk))
项目:eoj3    作者:ultmaster    | 项目源码 | 文件源码
def invalidate_user(user_id, contest_id=0):
    cache.delete_many([USER_TOTAL_COUNT.format(user=user_id, contest=contest_id),
                       USER_TOTAL_LIST.format(user=user_id, contest=contest_id),
                       USER_AC_COUNT.format(user=user_id, contest=contest_id),
                       USER_AC_DIFF_COUNT.format(user=user_id, contest=contest_id),
                       USER_AC_LIST.format(user=user_id, contest=contest_id)])