[Erp5-report] r34251 jm - /erp5/trunk/products/ERP5Type/Cache.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Apr 1 19:58:39 CEST 2010
Author: jm
Date: Thu Apr 1 19:58:39 2010
New Revision: 34251
URL: http://svn.erp5.org?rev=34251&view=rev
Log:
Add a decorator to use transactional cache
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=34251&r1=34250&r2=34251&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Cache.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Cache.py [utf8] Thu Apr 1 19:58:39 2010
@@ -291,3 +291,19 @@
# which the method is called would not be passed as first parameter.
return lambda *args, **kw: caching_method(*args, **kw)
return wrapped
+
+def transactional_cached(key_method=lambda *args: args):
+ def decorator(function):
+ key = repr(function)
+ def wrapper(*args, **kw):
+ cache = getTransactionalVariable(None).setdefault(key, {})
+ subkey = key_method(*args, **kw)
+ try:
+ return cache[subkey]
+ except KeyError:
+ cache[subkey] = result = function(*args, **kw)
+ return result
+ wrapper.__doc__ = function.__doc__
+ wrapper.__name__ = function.__name__
+ return wrapper
+ return decorator
More information about the Erp5-report
mailing list