[Erp5-report] r17755 - /erp5/trunk/products/ERP5Type/Base.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Nov 22 18:39:49 CET 2007
Author: alex
Date: Thu Nov 22 18:39:49 2007
New Revision: 17755
URL: http://svn.erp5.org?rev=17755&view=rev
Log:
_getTypeBasedMethod: replace CachingMethod by transactional variable based
cache
Modified:
erp5/trunk/products/ERP5Type/Base.py
Modified: erp5/trunk/products/ERP5Type/Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Base.py?rev=17755&r1=17754&r2=17755&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Base.py (original)
+++ erp5/trunk/products/ERP5Type/Base.py Thu Nov 22 18:39:49 2007
@@ -2812,7 +2812,7 @@
fallback_script_id : the script to use if nothing is found
"""
- def cached_getattr(portal_type, method_id):
+ def getScriptName(portal_type, method_id):
script_name_end = '_%s' % method_id
for script_name_begin in [portal_type, self.getMetaType(),
self.__class__.__name__]:
@@ -2820,17 +2820,27 @@
script = getattr(self, name, None)
if script is not None:
return name
- cached_getattr = CachingMethod(cached_getattr, id='Base__getattr',
- cache_factory='erp5_content_long')
# script_id should not be used any more, keep compatibility
if script_id is not None:
LOG('ERP5Type/Base.getTypeBaseMethod',0,
'DEPRECATED script_id parameter is used')
fallback_script_id=script_id
- # Look at a local script which
- # can return a new predicate.
- name = cached_getattr(self.getPortalType(), method_id)
+
+ # use a transactional variable to cache results within the same
+ # transaction
+ portal_type = self.getPortalType()
+ tv = getTransactionalVariable(self)
+ type_base_cache = tv.setdefault(
+ 'Base.type_based_cache', {})
+
+ cache_key = (portal_type, method_id)
+ try:
+ name = type_base_cache[cache_key]
+ except KeyError:
+ name = getScriptName(portal_type, method_id)
+ type_base_cache[cache_key] = name
+
if name is not None:
return getattr(self, name)
if fallback_script_id is not None:
More information about the Erp5-report
mailing list