缓存其它函数
同样地,使用 @cached
装饰器也能够缓存其它非视图函数的结果。唯一的要求是需要指定 key_prefix
,否则会使用请求路径(request.path)作为cache_key:
@cache.cached(timeout=50, key_prefix='all_comments')
def get_all_comments():
comments = do_serious_dbio()
return [x.author for x in comments]
cached_comments = get_all_comments()
当前内容版权归 wizardforcel 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 wizardforcel .