[Erp5-report] r29691 - in /erp5/trunk/products/ERP5Type: Cache.py ERP5Type.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Oct 15 21:05:47 CEST 2009
Author: kazuhiko
Date: Thu Oct 15 21:05:46 2009
New Revision: 29691
URL: http://svn.erp5.org?rev=29691&view=rev
Log:
* add 'cache_id_func' argument in CachingMethod.__init__ to specify how to generate cache_id, that is especially useful when you want to use for instance methods where args contain 'self'.
* use 'cache_id_func' in ERP5TypeInformation._getRawActionInformationList().
Modified:
erp5/trunk/products/ERP5Type/Cache.py
erp5/trunk/products/ERP5Type/ERP5Type.py
Modified: erp5/trunk/products/ERP5Type/Cache.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Cache.py?rev=29691&r1=29690&r2=29691&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Cache.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Cache.py [utf8] Thu Oct 15 21:05:46 2009
@@ -157,7 +157,8 @@
factories = {}
def __init__(self, callable_object, id, cache_duration=180,
- cache_factory=DEFAULT_CACHE_FACTORY):
+ cache_factory=DEFAULT_CACHE_FACTORY,
+ cache_id_func=None):
"""Wrap a callable object in a caching method.
callable_object must be callable.
@@ -175,6 +176,7 @@
self.callable_object = callable_object
self.cache_duration = cache_duration
self.cache_factory = cache_factory
+ self.cache_id_func = cache_id_func
def __call__(self, *args, **kwd):
"""Call the method or return cached value using appropriate cache plugin """
@@ -221,6 +223,9 @@
## generate cache id out of arguments passed.
## depending on arguments we may have different
## cache_id for same method_id
+ cache_id_func = self.cache_id_func
+ if cache_id_func is not None:
+ return cache_id_func(method_id, *args, **kwd)
return str((method_id, args, kwd))
allow_class(CachingMethod)
Modified: erp5/trunk/products/ERP5Type/ERP5Type.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/ERP5Type.py?rev=29691&r1=29690&r2=29691&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/ERP5Type.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/ERP5Type.py [utf8] Thu Oct 15 21:05:46 2009
@@ -530,7 +530,8 @@
_getRawActionInformationList = CachingMethod(
_getRawActionInformationList,
id='_getRawActionInformationList',
- cache_factory='erp5_content_long')
+ cache_factory='erp5_content_long',
+ cache_id_func=lambda method_id, *args, **kwd:str(method_id))
security.declarePrivate('getRawActionInformationList')
def getRawActionInformationList(self):
More information about the Erp5-report
mailing list