From 995a0479324e812140b4640191e8ea6748d9b97b Mon Sep 17 00:00:00 2001 From: Ivan Tyagov <ivan@nexedi.com> Date: Fri, 19 Oct 2012 11:22:44 +0300 Subject: [PATCH] Cache Bag is similar to Cache Factory so updateCache call is required. Add back wrongly removed volatile conversion caching. Use new set / get Cache bag API. --- product/ERP5/Document/BusinessTemplate.py | 3 ++- product/ERP5/mixin/cached_convertable.py | 7 +++++- .../ERP5OOo/tests/testOOoConversionCache.py | 24 +++++++++---------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py index 0b7abcf5f0..0707a3106a 100644 --- a/product/ERP5/Document/BusinessTemplate.py +++ b/product/ERP5/Document/BusinessTemplate.py @@ -1128,7 +1128,8 @@ class ObjectTemplateItem(BaseTemplateItem): container._mapTransform(obj) elif obj.meta_type in ('ERP5 Ram Cache', 'ERP5 Distributed Ram Cache',): - assert container.meta_type == 'ERP5 Cache Factory' + assert container.meta_type in ('ERP5 Cache Factory', + 'ERP5 Cache Bag') container.getParentValue().updateCache() elif (container.meta_type == 'CMF Skins Tool') and \ (old_obj is not None): diff --git a/product/ERP5/mixin/cached_convertable.py b/product/ERP5/mixin/cached_convertable.py index e27aeaefae..1452c3ebea 100644 --- a/product/ERP5/mixin/cached_convertable.py +++ b/product/ERP5/mixin/cached_convertable.py @@ -184,7 +184,12 @@ class CachedConvertableMixin: # get preferred cache factory or cache bag cache_factory = self._getCacheFactory() - if cache_factory is not None: + + # volatile case + if cache_factory is None: + return getattr(aq_base(self), 'temp_conversion_data', {})[cache_id] + + else: data_dict = cache_factory.get(cache_id, None) if data_dict: if isinstance(data_dict, tuple): diff --git a/product/ERP5OOo/tests/testOOoConversionCache.py b/product/ERP5OOo/tests/testOOoConversionCache.py index 930ca9a44b..07a66a0d84 100644 --- a/product/ERP5OOo/tests/testOOoConversionCache.py +++ b/product/ERP5OOo/tests/testOOoConversionCache.py @@ -265,19 +265,17 @@ class TestDocumentConversionCache(TestDocumentMixin): document.convert(**kw) cache_id = document._getCacheKey(**kw) cache_factory = document._getCacheFactory() - for cache_plugin in cache_factory.getCachePluginList(): - cache_entry = cache_plugin.get(cache_id, DEFAULT_CACHE_SCOPE) - data_dict = cache_entry.getValue() - #get data from cache - self.assertTrue(data_dict['content_md5']) - self.assertTrue(data_dict['conversion_md5']) - self.assertTrue(data_dict['mime']) - self.assertTrue(data_dict['data']) - self.assertTrue(data_dict['date']) - self.assertTrue(data_dict['size']) - #Change md5 manualy - data_dict['content_md5'] = 'Anything which is not md5' - cache_plugin.set(cache_id, DEFAULT_CACHE_SCOPE, data_dict, 100, 0) + data_dict = cache_factory.get(cache_id) + #get data from cache + self.assertTrue(data_dict['content_md5']) + self.assertTrue(data_dict['conversion_md5']) + self.assertTrue(data_dict['mime']) + self.assertTrue(data_dict['data']) + self.assertTrue(data_dict['date']) + self.assertTrue(data_dict['size']) + #Change md5 manualy + data_dict['content_md5'] = 'Anything which is not md5' + cache_factory.set(cache_id, data_dict) self.commit() self.assertRaises(KeyError, document.getConversion, format='html') -- 2.30.9