[Erp5-report] r29736 - /erp5/trunk/products/ERP5Type/Cache.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Oct 16 11:33:42 CEST 2009


Author: kazuhiko
Date: Fri Oct 16 11:33:41 2009
New Revision: 29736

URL: http://svn.erp5.org?rev=29736&view=rev
Log:
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.

Modified:
    erp5/trunk/products/ERP5Type/Cache.py

Modified: erp5/trunk/products/ERP5Type/Cache.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Cache.py?rev=29736&r1=29735&r2=29736&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Cache.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Cache.py [utf8] Fri Oct 16 11:33:41 2009
@@ -273,3 +273,18 @@
       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)




More information about the Erp5-report mailing list