[Django]関数ごとmemcacheに入れるための便利関数
- January 11th, 2010
- Posted in Python
- Write comment
こんな感じ。
def cache_func(key, timeout, func, *args, **kwargs):
# get the result from memcache
result = memcache.get(key)
if result:
return result
# get the result from orginal function
result = func(*args, **kwargs)
# set the result to memcache
memcache.set(key, result, timeout)
return result
使い方はこんな感じ。
def get_hogehoge(id, count):
return "%(id)s_%(count)s"
cache_timelines = lambda id, count: cache_func('cachekey_%(id)s_%(count)s' % dict(id=id, count=count), 60 * 10, get_hogehoge, id, count)
Popularity: 9% [?]
No comments yet.