Commit 532f2d9b authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

add caching_class_method_decorator that is based on ZSQLCatalog/SQLCatalog's...

add caching_class_method_decorator that is based on ZSQLCatalog/SQLCatalog's one, but str(self) will not be included in cache_id by default.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29736 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent eb734db2
...@@ -273,3 +273,18 @@ def clearCache(cache_factory_list=(DEFAULT_CACHE_FACTORY,)): ...@@ -273,3 +273,18 @@ def clearCache(cache_factory_list=(DEFAULT_CACHE_FACTORY,)):
for cp in cache_storage[cf_key].getCachePluginList(): for cp in cache_storage[cf_key].getCachePluginList():
cp.clearCache() cp.clearCache()
def generateCacheIdWithoutFirstArg(method_id, *args, **kwd):
# If we use CachingMethod as a class method, the first item of args
# is 'self' that can be ignored to create a cache id.
return str((method_id, args[1:], kwd))
class caching_class_method_decorator:
def __init__(self, *args, **kw):
self.args = args
kw.setdefault(
'cache_id_func', generateCacheIdWithoutFirstArg)
self.kw = kw
def __call__(self, method):
caching_method = CachingMethod(method, *self.args, **self.kw)
return lambda *args, **kw: caching_method(*args, **kw)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment