本文整理汇总了Python中util.cache.cache.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_template
def get_template(self, uri):
"""
Override of the base class for us to look into the
database tables for a template definition, if we can't find
one we'll return None which means "use default means" (aka filesystem)
"""
cache_key = "template_cache." + fasthash(microsite_get_value('site_domain') + '.' + uri)
template_text = cache.get(cache_key) # pylint: disable=maybe-no-member
if not template_text:
# cache is empty so pull template from DB and fill cache.
template_obj = MicrositeTemplate.get_template_for_microsite(
microsite_get_value('site_domain'),
uri
)
if not template_obj:
# We need to set something in the cache to improve performance
# of the templates stored in the filesystem as well
cache.set( # pylint: disable=maybe-no-member
cache_key, '##none', settings.MICROSITE_DATABASE_TEMPLATE_CACHE_TTL
)
return None
template_text = template_obj.template
cache.set( # pylint: disable=maybe-no-member
cache_key, template_text, settings.MICROSITE_DATABASE_TEMPLATE_CACHE_TTL
)
if template_text == '##none':
return None
return Template(
text=template_text
)
开发者ID:cpennington,项目名称:edx-platform,代码行数:35,代码来源:database.py
示例2: _get_value_from_cache
def _get_value_from_cache(key_name):
value = cache.get(key_name)
success = False
if value is None:
return success, value
try:
value = json.loads(value)
success = True
except:
pass
return success, value
开发者ID:Cgruppo,项目名称:edx-platform,代码行数:11,代码来源:open_ended_notifications.py
示例3: cached_has_permission
def cached_has_permission(user, permission, course_id=None):
"""
Call has_permission if it's not cached. A change in a user's role or
a role's permissions will only become effective after CACHE_LIFESPAN seconds.
"""
CACHE_LIFESPAN = 60
key = "permission_%d_%s_%s" % (user.id, str(course_id), permission)
val = cache.get(key, None)
if val not in [True, False]:
val = has_permission(user, permission, course_id=course_id)
cache.set(key, val, CACHE_LIFESPAN)
return val
开发者ID:AzizYosofi,项目名称:edx-platform,代码行数:12,代码来源:permissions.py
示例4: user_groups
def user_groups(user):
"""
TODO (vshnayder): This is not used. When we have a new plan for groups, adjust appropriately.
"""
if not user.is_authenticated():
return []
# TODO: Rewrite in Django
key = 'user_group_names_{user.id}'.format(user=user)
cache_expiration = 60 * 60 # one hour
# Kill caching on dev machines -- we switch groups a lot
group_names = cache.get(key)
if settings.DEBUG:
group_names = None
if group_names is None:
group_names = [u.name for u in UserTestGroup.objects.filter(users=user)]
cache.set(key, group_names, cache_expiration)
return group_names
开发者ID:BenjiLee,项目名称:edx-platform,代码行数:21,代码来源:views.py
示例5: course_structure
def course_structure(course_key, block_types=None):
"""
Retrieves the entire course structure, including information about all the blocks used in the
course if `block_types` is None else information about `block_types` will be returned only.
Final serialized information will be cached.
Args:
course_key: the CourseKey of the course we'd like to retrieve.
block_types: list of required block types. Possible values include sequential,
vertical, html, problem, video, and discussion. The type can also be
the name of a custom type of block used for the course.
Returns:
The serialized output of the course structure:
* root: The ID of the root node of the course structure.
* blocks: A dictionary that maps block IDs to a collection of
information about each block. Each block contains the following
fields.
* id: The ID of the block.
* type: The type of block. Possible values include sequential,
vertical, html, problem, video, and discussion. The type can also be
the name of a custom type of block used for the course.
* display_name: The display name configured for the block.
* graded: Whether or not the sequential or problem is graded. The
value is true or false.
* format: The assignment type.
* children: If the block has child blocks, a list of IDs of the child
blocks.
Raises:
CourseStructureNotAvailableError, CourseNotFoundError
"""
course = _retrieve_course(course_key)
modified_timestamp = models.CourseStructure.objects.filter(course_id=course_key).values('modified')
if modified_timestamp.exists():
cache_key = 'openedx.content.course_structures.api.v0.api.course_structure.{}.{}.{}'.format(
course_key, modified_timestamp[0]['modified'], '_'.join(block_types or [])
)
data = cache.get(cache_key) # pylint: disable=maybe-no-member
if data is not None:
return data
try:
requested_course_structure = models.CourseStructure.objects.get(course_id=course.id)
except models.CourseStructure.DoesNotExist:
pass
else:
structure = requested_course_structure.structure
if block_types is not None:
blocks = requested_course_structure.ordered_blocks
required_blocks = OrderedDict()
for usage_id, block_data in blocks.iteritems():
if block_data['block_type'] in block_types:
required_blocks[usage_id] = block_data
structure['blocks'] = required_blocks
data = CourseStructureSerializer(structure).data
cache.set(cache_key, data, None) # pylint: disable=maybe-no-member
return data
# If we don't have data stored, generate it and return an error.
tasks.update_course_structure.delay(unicode(course_key))
raise CourseStructureNotAvailableError
开发者ID:189140879,项目名称:edx-platform,代码行数:71,代码来源:api.py
注:本文中的util.cache.cache.get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论