From 532f2d9b2ce7279e2e2a3802402cca78e99a469d Mon Sep 17 00:00:00 2001 From: Kazuhiko Shiozaki <kazuhiko@nexedi.com> Date: Fri, 16 Oct 2009 09:33:41 +0000 Subject: [PATCH] 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 --- product/ERP5Type/Cache.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/product/ERP5Type/Cache.py b/product/ERP5Type/Cache.py index 56c753408b..6b86526985 100644 --- a/product/ERP5Type/Cache.py +++ b/product/ERP5Type/Cache.py @@ -273,3 +273,18 @@ def clearCache(cache_factory_list=(DEFAULT_CACHE_FACTORY,)): for cp in cache_storage[cf_key].getCachePluginList(): 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) -- 2.30.9