当前位置: 首页>>代码示例>>Python>>正文


Python cache.get_many方法代码示例

本文整理汇总了Python中django.core.cache.cache.get_many方法的典型用法代码示例。如果您正苦于以下问题:Python cache.get_many方法的具体用法?Python cache.get_many怎么用?Python cache.get_many使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.cache.cache的用法示例。


在下文中一共展示了cache.get_many方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_many_with_one_expired

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get_many [as 别名]
def test_get_many_with_one_expired(self):
        # Multiple cache keys can be returned using get_many
        the_cache = caches["no_cull"]
        the_cache.set("a", "a", 0.1)
        time.sleep(0.2)

        the_cache.set("b", "b")
        the_cache.set("c", "c")
        the_cache.set("d", "d")

        with self.assertNumQueries(1):
            value = the_cache.get_many(["a", "c", "d"])
        assert value == {"c": "c", "d": "d"}

        with self.assertNumQueries(1):
            value = the_cache.get_many(["a", "b", "e"])

        assert value == {"b": "b"} 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:20,代码来源:test_cache.py

示例2: get_user_course_permissions

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get_many [as 别名]
def get_user_course_permissions(user):
    """
    Return list of courses accessible by user or None to represent all courses.

    Arguments
        user (User) --  User for which course permissions should be returned
    """
    # ensure we don't request course permissions for users which would return all courses
    if user.is_superuser or user.is_staff:
        return None

    key_courses, key_last_updated = _get_course_permission_cache_keys(user)
    keys = [key_courses, key_last_updated]

    # Check the cache for data
    values = cache.get_many(keys)
    courses = values.get(key_courses, [])

    # If data is not in the cache, refresh the permissions and validate against the new data.
    if not values.get(key_last_updated):
        courses = _refresh_user_course_permissions(user)

    return courses 
开发者ID:edx,项目名称:edx-analytics-dashboard,代码行数:25,代码来源:permissions.py

示例3: get_moderation_tasks

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get_many [as 别名]
def get_moderation_tasks(self):
        """Gets a list of moderation task types that are pending."""
        messages_key = '%s_messages_to_mod' % self.pk
        groups_key = '%s_groups_to_mod' % self.pk
        mods = cache.get_many([messages_key, groups_key])
        if messages_key not in mods:
            messages_to_moderate = self.messages_to_moderate.count()
            cache.set(messages_key, messages_to_moderate, 600)
            mods[messages_key] = messages_to_moderate
        if groups_key not in mods:
            groups_to_moderate = self.group_join_requests_to_moderate().count()
            cache.set(groups_key, groups_to_moderate, 600)
            mods[groups_key] = groups_to_moderate
        return {
            'groups_to_mod': mods[groups_key],
            'messages_to_mod': mods[messages_key]
        } 
开发者ID:ofa,项目名称:connect,代码行数:19,代码来源:models.py

示例4: get_cleaned_articles

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get_many [as 别名]
def get_cleaned_articles(articles) -> dict:
    from_cache = cache.get_many([cache_id_to_key(a.id) for a in articles])
    rv = {cache_key_to_id(k): v for k, v in from_cache.items()}

    to_cache = dict()
    for article in articles:
        if article.id in rv:
            continue

        cleaned = html_processing.clean_article(
            article.content,
            base_url=article.feed.uri
        )
        rv[article.id] = cleaned
        to_cache[cache_id_to_key(article.id)] = cleaned

    if to_cache:
        cache.set_many(to_cache, timeout=7200)

    return rv 
开发者ID:NicolasLM,项目名称:feedsubs,代码行数:22,代码来源:caching.py

示例5: lookup_cache

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get_many [as 别名]
def lookup_cache(self, content_strings):
        """
        Lookup cache keys
        """
        cache_result = cache.get_many(
            [self.CACHE_KEY + content_string for content_string in content_strings]
        )

        # Remove the cache_key prefix
        values = {}
        for key, value in cache_result.items():
            values[key[len(self.CACHE_KEY) :]] = value

        return values 
开发者ID:webkom,项目名称:lego,代码行数:16,代码来源:attr_cache.py

示例6: test_get_many

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get_many [as 别名]
def test_get_many(self):
        # Multiple cache keys can be returned using get_many
        cache.set("a", "a")
        cache.set("b", "b")
        cache.set("c", "c")
        cache.set("d", "d")

        with self.assertNumQueries(1):
            value = cache.get_many(["a", "c", "d"])
        assert value == {"a": "a", "c": "c", "d": "d"}

        with self.assertNumQueries(1):
            value = cache.get_many(["a", "b", "e"])

        assert value == {"a": "a", "b": "b"} 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:17,代码来源:test_cache.py

示例7: test_delete_with_prefix_with_no_reverse_works

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get_many [as 别名]
def test_delete_with_prefix_with_no_reverse_works(self):
        cache.set_many({"K1": "value", "K2": "value2", "B2": "Anothervalue"})
        assert cache.delete_with_prefix("K") == 2
        assert cache.get_many(["K1", "K2", "B2"]) == {"B2": "Anothervalue"} 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:6,代码来源:test_cache.py

示例8: get_context_data

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get_many [as 别名]
def get_context_data(self, *args, **kwargs):
        context = super(InboxView, self).get_context_data(*args, **kwargs)

        object_list = []
        object_id_list = []
        for email in context["page_obj"].object_list:
            object_list.append(email)
            object_id_list.append(email.id)

        if len(object_id_list) == 0:
            return context

        headers = cache.get_many(object_id_list, version="email-header")

        missing_list = set(object_id_list) - set(headers.keys())
        if len(missing_list) > 0:
            missing_headers = models.Header.objects.filter(part__parent=None, part__email__in=missing_list)
            missing_headers = missing_headers.get_many("Subject", "From", group_by="part__email_id")
            headers.update(missing_headers)
            cache.set_many(missing_headers, version="email-header", timeout=None)

        for email in object_list:
            header_set = headers[email.id]
            email.subject = header_set.get("Subject")
            email.sender = header_set["From"]

        inbox = getattr(self, 'inbox_obj', None)
        if inbox is not None:
            inbox = inbox.id

        set_emails_to_seen.delay(object_id_list, self.request.user.id, inbox)
        return context 
开发者ID:Inboxen,项目名称:Inboxen,代码行数:34,代码来源:inbox.py

示例9: counter_full

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get_many [as 别名]
def counter_full(self, request):
        now = timezone.now()

        keys = [self.make_key(request, now - timedelta(minutes=i)) for i in range(self.window)]
        counters = cache.get_many(keys)
        if sum(counters.values()) >= self.max_count:
            self.full_callback(request)
            self.counter_increase(request)
            return True

        return False 
开发者ID:Inboxen,项目名称:Inboxen,代码行数:13,代码来源:ratelimit.py

示例10: get_queryset

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get_many [as 别名]
def get_queryset(self):
    contest_participants = {user.user_id: user.comment for user in
                            ContestParticipant.objects.filter(contest=self.contest).select_related('user',
                                                                                                   'contest').all()}
    qs = self.contest.submission_set.filter(status=SubmissionStatus.ACCEPTED). \
      defer("code", "status_message", "status_detail").all()
    available = set(
      cache.get_many(list(map(lambda x: BALLOON_CACHE_NAME % (x.contest_id, x.author_id, x.problem_id), qs))).keys())
    self.contest.add_contest_problem_to_submissions(qs)
    for submission in qs:
      submission.username = contest_participants.get(submission.author_id, "INVALID")
      if BALLOON_CACHE_NAME % (submission.contest_id, submission.author_id, submission.problem_id) in available:
        submission.ok = True
    return qs 
开发者ID:F0RE1GNERS,项目名称:eoj3,代码行数:16,代码来源:submission.py


注:本文中的django.core.cache.cache.get_many方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。