本文整理汇总了Python中agilito.models.Project.cache_id方法的典型用法代码示例。如果您正苦于以下问题:Python Project.cache_id方法的具体用法?Python Project.cache_id怎么用?Python Project.cache_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类agilito.models.Project
的用法示例。
在下文中一共展示了Project.cache_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: f_cached
# 需要导入模块: from agilito.models import Project [as 别名]
# 或者: from agilito.models.Project import cache_id [as 别名]
def f_cached(*args, **kwargs):
global CACHE_ENABLED
self = args[0]
if not CACHE_ENABLED or not hasattr(self, 'project_id'):
return f(*args, **kwargs)
params = f.func_code.co_varnames[:f.func_code.co_argcount]
vardict = dict(zip(params, ['<None>' for d in params]))
vardict.update(dict(zip(f.func_code.co_varnames, args)))
vardict.update(kwargs)
# replace 'self' with module:class:id:method
obj = '%s.%s.%s(%s' % (self.__class__.__module__, self.__class__.__name__, f.__name__, str(self.id))
vardict['self'] = obj
from agilito.models import Project
pv = Project.cache_id(self.project_id)
key = CACHE_PREFIX + '.'
key += ','.join([str(vardict[v]) for v in params]) + ')'
v = cache.get(key + '#version')
if v == pv:
v = cache.get(key + '#value')
if not v is None:
return v
v = f(*args, **kwargs)
cache.set(key + '#version', pv, 1000000)
cache.set(key + '#value', v, 1000000)
return v
示例2: f_cached
# 需要导入模块: from agilito.models import Project [as 别名]
# 或者: from agilito.models.Project import cache_id [as 别名]
def f_cached(*args, **kwargs):
global CACHE_ENABLED
if not CACHE_ENABLED:
return f(*args, **kwargs)
params = f.func_code.co_varnames[1:f.func_code.co_argcount]
vardict = dict(zip(params, ['<default>' for d in params]))
vardict.update(dict(zip(params, args[1:])))
vardict.update(kwargs)
u = args[0].user # request.user
pv = Project.cache_id(vardict["project_id"])
key = "%s.agilito.views.%s(%s)" % (CACHE_PREFIX, f.__name__, ",".join([str(vardict[v]) for v in params]))
v = cache.get(key + "#version")
if v == pv:
v = cache.get(key + "#value")
if not v is None:
return v
v = f(*args, **kwargs)
cache.set(key + '#version', pv, 1000000)
cache.set(key + '#value', v, 1000000)
return v