當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。