[Erp5-report] r6882 - in /erp5/trunk/products/ERP5Type: Cache.py tests/testERP5Type.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Apr 24 14:04:06 CEST 2006
Author: jerome
Date: Mon Apr 24 14:04:01 2006
New Revision: 6882
URL: http://svn.erp5.org?rev=6882&view=rev
Log:
clearCache now supports method_id argument to clear the cache of this CachingMethod only
Modified:
erp5/trunk/products/ERP5Type/Cache.py
erp5/trunk/products/ERP5Type/tests/testERP5Type.py
Modified: erp5/trunk/products/ERP5Type/Cache.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Cache.py?rev=6882&r1=6881&r2=6882&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Cache.py (original)
+++ erp5/trunk/products/ERP5Type/Cache.py Mon Apr 24 14:04:01 2006
@@ -147,8 +147,19 @@
allow_class(CachingMethod)
-def clearCache():
- CachingMethod.cached_object_dict.clear()
+def clearCache(method_id=None):
+ """Clear the cache.
+ If method_id is specified, it clears the cache only for this method,
+ otherwise, it clears the whole cache."""
+ if method_id is None:
+ CachingMethod.cached_object_dict.clear()
+ else:
+ caching_method_keys = CachingMethod.cached_object_dict.keys()
+ for key in caching_method_keys :
+ # CachingMethod dict contains a string representation of a list
+ # of tuples keys.
+ if method_id in key :
+ del CachingMethod.cached_object_dict[key]
# TransactionCache is a cache per transaction. The purpose of this cache is
# to accelerate some heavy read-only operations. Note that this must not be
Modified: erp5/trunk/products/ERP5Type/tests/testERP5Type.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/testERP5Type.py?rev=6882&r1=6881&r2=6882&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/testERP5Type.py (original)
+++ erp5/trunk/products/ERP5Type/tests/testERP5Type.py Mon Apr 24 14:04:01 2006
@@ -200,8 +200,35 @@
self.assertEquals(organisation.corporate_name,'Nexedi')
self.assertEquals(organisation.default_telephone.corporate_name,'Toto')
-
-
+ def test_06_CachingMethod(self):
+ """Tests Caching methods."""
+ cached_var1 = cached_var1_orig = 'cached_var1'
+ cached_var2 = cached_var2_orig = 'cached_var2'
+
+ def _cache1():
+ return cached_var1
+ def _cache2():
+ return cached_var2
+
+ from Products.ERP5Type.Cache import CachingMethod, clearCache
+ cache1 = CachingMethod(_cache1, id='_cache1')
+ cache2 = CachingMethod(_cache2, id='_cache2')
+
+ self.assertEquals(cache1(), cached_var1)
+ self.assertEquals(cache2(), cached_var2)
+
+ cached_var1 = 'cached_var1 (modified)'
+ cached_var2 = 'cached_var2 (modified)'
+ self.assertEquals(cache1(), cached_var1_orig)
+
+ # clearCache with a method argument only clear this cache
+ clearCache(method_id = '_cache1')
+ self.assertEquals(cache1(), cached_var1)
+ self.assertEquals(cache2(), cached_var2_orig)
+
+ # clearCache with no arguments clear all caches
+ clearCache()
+ self.assertEquals(cache2(), cached_var2)
if __name__ == '__main__':
framework()
More information about the Erp5-report
mailing list