diff --git a/product/ERP5Type/Cache.py b/product/ERP5Type/Cache.py index 534cff0239ad9e96e63bcdf565e27a0d42d4dab7..b1519bcdf6d514bddc9348bd47fdba30eb965229 100644 --- a/product/ERP5Type/Cache.py +++ b/product/ERP5Type/Cache.py @@ -207,13 +207,14 @@ class CachingMethod: *args, **kwd) return value - def delete(self, id=None, cache_factory=None, scope=DEFAULT_CACHE_SCOPE): - """ Delete cache key. """ - if id is None: - id = self.id - if cache_factory is None: - cache_factory = self.cache_factory - cache_id = self.generateCacheId(id) + def delete(self, *args, **kwd): + """ Delete cache key. + accept same arguments as __call__ to clear + the cache entry with the same cache_id + """ + cache_factory = self.cache_factory + scope = kwd.pop('scope', DEFAULT_CACHE_SCOPE) + cache_id = self.generateCacheId(self.id, *args, **kwd) cache_factory = CachingMethod.factories[cache_factory] for cp in cache_factory.getCachePluginList(): cp.delete(cache_id, scope) diff --git a/product/ERP5Type/tests/testCacheTool.py b/product/ERP5Type/tests/testCacheTool.py index d83355402ee0f34cc74cad24438a5ce922675484..1fd88b67aa54566feeef6f8903f0d3cf18846a5b 100644 --- a/product/ERP5Type/tests/testCacheTool.py +++ b/product/ERP5Type/tests/testCacheTool.py @@ -261,6 +261,22 @@ return result ## Cache cleared shouldn't be previously cached self.assert_(1.0 < calculation_time) + # Test delete method on CachingMethod + print "\n\tCalculation time (3rd call)", calculation_time + # fill the cache + original = my_cache(nb_iterations, portal_path=('', portal.getId())) + + # Purge the Caching Method + my_cache.delete(nb_iterations, portal_path=('', portal.getId())) + + # Check that result is computed + start = time.time() + original = my_cache(nb_iterations, portal_path=('', portal.getId())) + end = time.time() + calculation_time = end-start + print "\n\tCalculation time (4th call)", calculation_time + self.assert_(1.0 < calculation_time) + def test_03_cachePersistentObjects(self): # storing persistent objects in cache is not allowed, but this check is # only performed in unit tests.