• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python request_cache.get_cache函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中request_cache.get_cache函数的典型用法代码示例。如果您正苦于以下问题:Python get_cache函数的具体用法?Python get_cache怎么用?Python get_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: _update_cache

 def _update_cache(cls, course_key, visible_blocks):
     """
     Adds a specific set of visible blocks to the request cache.
     This assumes that prefetch has already been called.
     """
     get_cache(cls.CACHE_NAMESPACE)[cls._cache_key(course_key)].update(
         {visible_block.hashed: visible_block for visible_block in visible_blocks}
     )
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:8,代码来源:models.py


示例2: get_template_request_context

def get_template_request_context(request=None):
    """
    Returns the template processing context to use for the current request,
    or returns None if there is not a current request.
    """

    if request is None:
        request = get_current_request()

    if request is None:
        return None

    request_cache_dict = request_cache.get_cache('edxmako')
    cache_key = "request_context"
    if cache_key in request_cache_dict:
        return request_cache_dict[cache_key]

    context = RequestContext(request)

    context['is_secure'] = request.is_secure()
    context['site'] = safe_get_host(request)

    request_cache_dict[cache_key] = context

    return context
开发者ID:lduarte1991,项目名称:edx-platform,代码行数:25,代码来源:request_context.py


示例3: __enter__

    def __enter__(self):

        connection = transaction.get_connection(self.using)

        cache = request_cache.get_cache(OUTER_ATOMIC_CACHE_NAME)

        # By default it is enabled.
        enable = True
        # If name is set it is only enabled if requested by calling enable_named_outer_atomic().
        if self.name:
            enable = cache.get(self.name, False)

        if enable:
            # TestCase setup nests tests in two atomics - one for the test class and one for the individual test.
            # The outermost atomic starts a transaction - so does not have a savepoint.
            # The inner atomic starts a savepoint around the test.
            # So, for tests only, there should be exactly one savepoint_id and two atomic_for_testcase_calls.
            # atomic_for_testcase_calls below is added in a monkey-patch for tests only.
            if self.ALLOW_NESTED and (self.atomic_for_testcase_calls - len(connection.savepoint_ids)) < 1:
                raise transaction.TransactionManagementError('Cannot be inside an atomic block.')

            # Otherwise, this shouldn't be nested in any atomic block.
            if not self.ALLOW_NESTED and connection.in_atomic_block:
                raise transaction.TransactionManagementError('Cannot be inside an atomic block.')

            # This will set the transaction isolation level to READ COMMITTED for the next transaction.
            if self.read_committed is True:
                if connection.vendor == 'mysql':
                    cursor = connection.cursor()
                    cursor.execute("SET TRANSACTION ISOLATION LEVEL READ COMMITTED")

        super(OuterAtomic, self).__enter__()
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:32,代码来源:db.py


示例4: get_group_info_for_cohort

def get_group_info_for_cohort(cohort, use_cached=False):
    """
    Get the ids of the group and partition to which this cohort has been linked
    as a tuple of (int, int).

    If the cohort has not been linked to any group/partition, both values in the
    tuple will be None.

    The partition group info is cached for the duration of a request. Pass
    use_cached=True to use the cached value instead of fetching from the
    database.
    """
    cache = request_cache.get_cache(u"cohorts.get_group_info_for_cohort")
    cache_key = unicode(cohort.id)

    if use_cached and cache_key in cache:
        return cache[cache_key]

    cache.pop(cache_key, None)

    try:
        partition_group = CourseUserGroupPartitionGroup.objects.get(course_user_group=cohort)
        return cache.setdefault(cache_key, (partition_group.group_id, partition_group.partition_id))
    except CourseUserGroupPartitionGroup.DoesNotExist:
        pass

    return cache.setdefault(cache_key, (None, None))
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:27,代码来源:cohorts.py


示例5: user_timezone_locale_prefs

def user_timezone_locale_prefs(request):
    """
    Checks if request has an authenticated user.
    If so, sends set (or none if unset) time_zone and language prefs.

    This interacts with the DateUtils to either display preferred or attempt to determine
    system/browser set time_zones and languages

    """
    cached_value = request_cache.get_cache(CACHE_NAME)
    if not cached_value:
        user_prefs = {
            'user_timezone': None,
            'user_language': None,
        }
        if hasattr(request, 'user') and request.user.is_authenticated():
            try:
                user_preferences = get_user_preferences(request.user)
            except (UserNotFound, UserAPIInternalError):
                cached_value.update(user_prefs)
            else:
                user_prefs = {
                    key: user_preferences.get(pref_name, None)
                    for key, pref_name in RETRIEVABLE_PREFERENCES.iteritems()
                }

        cached_value.update(user_prefs)
    return cached_value
开发者ID:Colin-Fredericks,项目名称:edx-platform,代码行数:28,代码来源:context_processor.py


示例6: get_template_request_context

def get_template_request_context(request=None):
    """
    Returns the template processing context to use for the current request,
    or returns None if there is not a current request.
    """

    if request is None:
        request = get_current_request()

    if request is None:
        return None

    request_cache_dict = request_cache.get_cache('edxmako')
    cache_key = "request_context"
    if cache_key in request_cache_dict:
        return request_cache_dict[cache_key]

    context = RequestContext(request)

    context['is_secure'] = request.is_secure()
    context['site'] = safe_get_host(request)

    # This used to happen when a RequestContext object was initialized but was
    # moved to a different part of the logic when template engines were introduced.
    # Since we are not using template engines we do this here.
    # https://github.com/django/django/commit/37505b6397058bcc3460f23d48a7de9641cd6ef0
    for processor in get_template_context_processors():
        context.update(processor(request))

    request_cache_dict[cache_key] = context

    return context
开发者ID:AndreySonetico,项目名称:edx-platform,代码行数:32,代码来源:request_context.py


示例7: create_new_event_transaction_id

def create_new_event_transaction_id():
    """
    Sets the event transaction id to a newly-
    generated UUID.
    """
    new_id = uuid4()
    get_cache('event_transaction')['id'] = new_id
    return new_id
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:8,代码来源:event_transaction_utils.py


示例8: set_event_transaction_id

def set_event_transaction_id(new_id):
    """
    Sets the event transaction id to a UUID object
    generated from new_id.
    new_id must be a parsable string version
    of a UUID.
    """
    get_cache('event_transaction')['id'] = UUID(new_id)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:8,代码来源:event_transaction_utils.py


示例9: prefetch

 def prefetch(cls, course_id, users):
     """
     Prefetches grades for the given users for the given course.
     """
     get_cache(cls.CACHE_NAMESPACE)[cls._cache_key(course_id)] = {
         grade.user_id: grade
         for grade in
         cls.objects.filter(user_id__in=[user.id for user in users], course_id=course_id)
     }
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:9,代码来源:models.py


示例10: _initialize_cache

 def _initialize_cache(cls, course_key):
     """
     Prefetches visible blocks for the given course and stores in the cache.
     Returns a dictionary mapping hashes of these block records to the
     block record objects.
     """
     prefetched = {record.hashed: record for record in cls.objects.filter(course_id=course_key)}
     get_cache(cls.CACHE_NAMESPACE)[cls._cache_key(course_key)] = prefetched
     return prefetched
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:9,代码来源:models.py


示例11: prefetch

    def prefetch(cls, users):
        roles_by_user = defaultdict(set)
        get_cache(cls.CACHE_NAMESPACE)[cls.CACHE_KEY] = roles_by_user

        for role in CourseAccessRole.objects.filter(user__in=users).select_related('user'):
            roles_by_user[role.user.id].add(role)

        users_without_roles = filter(lambda u: u.id not in roles_by_user, users)
        for user in users_without_roles:
            roles_by_user[user.id] = set()
开发者ID:auvipy,项目名称:edx-platform,代码行数:10,代码来源:roles.py


示例12: get_override

 def get_override(cls, user_id, usage_key):
     prefetch_values = get_cache(cls._CACHE_NAMESPACE).get((user_id, str(usage_key.course_key)), None)
     if prefetch_values is not None:
         return prefetch_values.get(usage_key)
     try:
         return cls.objects.get(
             grade__user_id=user_id,
             grade__course_id=usage_key.course_key,
             grade__usage_key=usage_key,
         )
     except PersistentSubsectionGradeOverride.DoesNotExist:
         pass
开发者ID:dehamzah,项目名称:edx-platform,代码行数:12,代码来源:models.py


示例13: bulk_read

    def bulk_read(cls, course_key):
        """
        Reads and returns all visible block records for the given course from
        the cache.  The cache is initialize with the visible blocks for this
        course if no entry currently exists.has no entry for this course,
        the cache is updated.

        Arguments:
            course_key: The course identifier for the desired records
        """
        prefetched = get_cache(cls.CACHE_NAMESPACE).get(cls._cache_key(course_key))
        if not prefetched:
            prefetched = cls._initialize_cache(course_key)
        return prefetched
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:14,代码来源:models.py


示例14: cached_get_or_create

 def cached_get_or_create(cls, blocks):
     prefetched = get_cache(cls._CACHE_NAMESPACE).get(cls._cache_key(blocks.course_key))
     if prefetched is not None:
         model = prefetched.get(blocks.hash_value)
         if not model:
             model = cls.objects.create(
                 hashed=blocks.hash_value, blocks_json=blocks.json_value, course_id=blocks.course_key,
             )
             cls._update_cache(blocks.course_key, [model])
     else:
         model, _ = cls.objects.get_or_create(
             hashed=blocks.hash_value,
             defaults={u'blocks_json': blocks.json_value, u'course_id': blocks.course_key},
         )
     return model
开发者ID:dehamzah,项目名称:edx-platform,代码行数:15,代码来源:models.py


示例15: get_current_ccx

def get_current_ccx(course_key):
    """
    Return the ccx that is active for this course.

    course_key is expected to be an instance of an opaque CourseKey, a
    ValueError is raised if this expectation is not met.
    """
    if not isinstance(course_key, CourseKey):
        raise ValueError("get_current_ccx requires a CourseKey instance")

    if not isinstance(course_key, CCXLocator):
        return None

    ccx_cache = request_cache.get_cache('ccx')
    if course_key not in ccx_cache:
        ccx_cache[course_key] = CustomCourseForEdX.objects.get(pk=course_key.ccx)

    return ccx_cache[course_key]
开发者ID:benpatterson,项目名称:edx-platform,代码行数:18,代码来源:overrides.py


示例16: prefetch

    def prefetch(cls, course_id, users):
        """
        Prefetches the value of the course tags for the specified users
        for the specified course_id.

        Args:
            users: iterator of User objects
            course_id: course identifier (CourseKey)

        Returns:
            course_tags: a dict of dicts,
                where the primary key is the user's id
                and the secondary key is the course tag's key
        """
        course_tags = defaultdict(dict)
        for tag in UserCourseTag.objects.filter(user__in=users, course_id=course_id).select_related('user'):
            course_tags[tag.user.id][tag.key] = tag.value
        get_cache(cls.CACHE_NAMESPACE)[cls._cache_key(course_id)] = course_tags
开发者ID:lduarte1991,项目名称:edx-platform,代码行数:18,代码来源:api.py


示例17: enable_named_outer_atomic

def enable_named_outer_atomic(*names):
    """
    Enable outer_atomics with names.

    Can be used either as a decorator or a context manager.
    See docstring of outer_atomic for details.

    Arguments:
        names (variable-lenght argument list): Names of outer_atomics.
    """
    if len(names) == 0:
        raise ValueError("At least one name must be specified.")

    cache = request_cache.get_cache(OUTER_ATOMIC_CACHE_NAME)

    for name in names:
        cache[name] = True
    yield
    for name in names:
        del cache[name]
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:20,代码来源:db.py


示例18: _get_overrides_for_ccx

def _get_overrides_for_ccx(ccx):
    """
    Returns a dictionary mapping field name to overriden value for any
    overrides set on this block for this CCX.
    """
    overrides_cache = request_cache.get_cache('ccx-overrides')

    if ccx not in overrides_cache:
        overrides = {}
        query = CcxFieldOverride.objects.filter(
            ccx=ccx,
        )

        for override in query:
            block_overrides = overrides.setdefault(override.location, {})
            block_overrides[override.field] = json.loads(override.value)

        overrides_cache[ccx] = overrides

    return overrides_cache[ccx]
开发者ID:benpatterson,项目名称:edx-platform,代码行数:20,代码来源:overrides.py


示例19: read

    def read(cls, user_id, course_id):
        """
        Reads a grade from database

        Arguments:
            user_id: The user associated with the desired grade
            course_id: The id of the course associated with the desired grade

        Raises PersistentCourseGrade.DoesNotExist if applicable
        """
        try:
            prefetched_grades = get_cache(cls.CACHE_NAMESPACE)[cls._cache_key(course_id)]
            try:
                return prefetched_grades[user_id]
            except KeyError:
                # user's grade is not in the prefetched list, so
                # assume they have no grade
                raise cls.DoesNotExist
        except KeyError:
            # grades were not prefetched for the course, so fetch it
            return cls.objects.get(user_id=user_id, course_id=course_id)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:21,代码来源:models.py


示例20: process_response

    def process_response(self, __, response):
        """
        If request is from mobile native app, then add version related info to response headers.

        Returns:
            Http response: with additional headers;
                1. EDX-APP-LATEST-VERSION; if user app version < latest available version
                2. EDX-APP-VERSION-LAST-SUPPORTED-DATE; if user app version < min supported version and
                   timestamp < expiry of that version
        """
        request_cache_dict = request_cache.get_cache(self.REQUEST_CACHE_NAME)
        if request_cache_dict:
            last_supported_date = request_cache_dict[self.LAST_SUPPORTED_DATE_HEADER]
            if last_supported_date != self.NO_LAST_SUPPORTED_DATE:
                response[self.LAST_SUPPORTED_DATE_HEADER] = last_supported_date.isoformat()
            latest_version = request_cache_dict[self.LATEST_VERSION_HEADER]
            user_app_version = request_cache_dict[self.USER_APP_VERSION]
            if (latest_version != self.NO_LATEST_VERSION and
                    parsed_version(user_app_version) < parsed_version(latest_version)):
                response[self.LATEST_VERSION_HEADER] = latest_version
        return response
开发者ID:10clouds,项目名称:edx-platform,代码行数:21,代码来源:middleware.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python middleware.RequestCache类代码示例发布时间:2022-05-26
下一篇:
Python models.Request类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap