Commit a332cc15 authored by Nicolas Delaby's avatar Nicolas Delaby

* Delete clearConversionCache from API.

* Compute new cache key with revision (incremental counter based on
edit transtions of edit_workflow)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34878 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cdde1513
...@@ -131,7 +131,6 @@ class File(Document, CMFFile, CachedConvertableMixin): ...@@ -131,7 +131,6 @@ class File(Document, CMFFile, CachedConvertableMixin):
getcontentlength = get_size getcontentlength = get_size
def _setFile(self, data, precondition=None): def _setFile(self, data, precondition=None):
self.clearConversionCache()
CMFFile._edit(self, precondition=precondition, file=data) CMFFile._edit(self, precondition=precondition, file=data)
security.declareProtected(Permissions.ModifyPortalContent,'setFile') security.declareProtected(Permissions.ModifyPortalContent,'setFile')
...@@ -170,7 +169,6 @@ class File(Document, CMFFile, CachedConvertableMixin): ...@@ -170,7 +169,6 @@ class File(Document, CMFFile, CachedConvertableMixin):
security.declareProtected(Permissions.ModifyPortalContent,'PUT') security.declareProtected(Permissions.ModifyPortalContent,'PUT')
def PUT(self, REQUEST, RESPONSE): def PUT(self, REQUEST, RESPONSE):
self.clearConversionCache()
CMFFile.PUT(self, REQUEST, RESPONSE) CMFFile.PUT(self, REQUEST, RESPONSE)
# DAV Support # DAV Support
......
...@@ -125,13 +125,6 @@ class TextDocument(Document, TextContent): ...@@ -125,13 +125,6 @@ class TextDocument(Document, TextContent):
security.declareProtected( Permissions.ModifyPortalContent, 'edit' ) security.declareProtected( Permissions.ModifyPortalContent, 'edit' )
edit = WorkflowMethod( _edit ) edit = WorkflowMethod( _edit )
security.declareProtected(Permissions.ModifyPortalContent, '_setTextContent')
def _setTextContent(self, *args, **kw):
"""Call Clear conversion cache when edit text_content
"""
self.clearConversionCache()
self._baseSetTextContent(*args, **kw)
# Default Display # Default Display
security.declareProtected(Permissions.View, 'index_html') security.declareProtected(Permissions.View, 'index_html')
def index_html(self, REQUEST, RESPONSE, format=None, **kw): def index_html(self, REQUEST, RESPONSE, format=None, **kw):
......
...@@ -233,11 +233,6 @@ class IDocument(Interface): ...@@ -233,11 +233,6 @@ class IDocument(Interface):
links (in combindation with populate). links (in combindation with populate).
""" """
def clearConversionCache():
"""Clear cache (invoked by interaction workflow upon file upload
needed here to overwrite class attribute with instance attrs
"""
def hasConversion(**kw): def hasConversion(**kw):
"""Return a boolean if conversion is cached """Return a boolean if conversion is cached
""" """
......
...@@ -87,17 +87,7 @@ class CachedConvertableMixin: ...@@ -87,17 +87,7 @@ class CachedConvertableMixin:
http://pypi.python.org/pypi/uuid/ to generate http://pypi.python.org/pypi/uuid/ to generate
a uuid stored as private property. a uuid stored as private property.
""" """
return aq_base(self).getUid() return '%s:%s' % (aq_base(self).getUid(), self.getRevision())
security.declareProtected(Permissions.ModifyPortalContent, 'clearConversionCache')
def clearConversionCache(self):
"""
"""
if self.isTempObject():
self.temp_conversion_data = {}
return
for cache_plugin in self._getCacheFactory().getCachePluginList():
cache_plugin.delete(self._getCacheKey(), DEFAULT_CACHE_SCOPE)
security.declareProtected(Permissions.View, 'hasConversion') security.declareProtected(Permissions.View, 'hasConversion')
def hasConversion(self, **kw): def hasConversion(self, **kw):
...@@ -129,7 +119,7 @@ class CachedConvertableMixin: ...@@ -129,7 +119,7 @@ class CachedConvertableMixin:
def setConversion(self, data, mime=None, calculation_time=None, **kw): def setConversion(self, data, mime=None, calculation_time=None, **kw):
""" """
""" """
cache_id = self.generateCacheId(**kw) cache_id = '%s%s' % (self._getCacheKey(), self.generateCacheId(**kw))
if self.isTempObject(): if self.isTempObject():
if getattr(aq_base(self), 'temp_conversion_data', None) is None: if getattr(aq_base(self), 'temp_conversion_data', None) is None:
self.temp_conversion_data = {} self.temp_conversion_data = {}
...@@ -139,31 +129,27 @@ class CachedConvertableMixin: ...@@ -139,31 +129,27 @@ class CachedConvertableMixin:
cache_duration = cache_factory.cache_duration cache_duration = cache_factory.cache_duration
if data is not None: if data is not None:
for cache_plugin in cache_factory.getCachePluginList(): for cache_plugin in cache_factory.getCachePluginList():
try: cache_plugin.set(cache_id, DEFAULT_CACHE_SCOPE,
cache_entry = cache_plugin.get(self._getCacheKey(), DEFAULT_CACHE_SCOPE) (self.getContentMd5(), mime, aq_base(data)),
cache_dict = cache_entry.getValue() calculation_time=calculation_time,
except KeyError:
cache_dict = {}
cache_dict.update({cache_id: (self.getContentMd5(), mime, aq_base(data))})
cache_plugin.set(self._getCacheKey(), DEFAULT_CACHE_SCOPE,
cache_dict, calculation_time=calculation_time,
cache_duration=cache_duration) cache_duration=cache_duration)
security.declareProtected(Permissions.View, 'getConversion') security.declareProtected(Permissions.View, 'getConversion')
def getConversion(self, **kw): def getConversion(self, **kw):
""" """
""" """
cache_id = self.generateCacheId(**kw) cache_id = '%s%s' % (self._getCacheKey(), self.generateCacheId(**kw))
if self.isTempObject(): if self.isTempObject():
return getattr(aq_base(self), 'temp_conversion_data', {})[cache_id] return getattr(aq_base(self), 'temp_conversion_data', {})[cache_id]
for cache_plugin in self._getCacheFactory().getCachePluginList(): for cache_plugin in self._getCacheFactory().getCachePluginList():
cache_entry = cache_plugin.get(self._getCacheKey(), DEFAULT_CACHE_SCOPE) cache_entry = cache_plugin.get(cache_id, DEFAULT_CACHE_SCOPE)
data_list = cache_entry.getValue().get(cache_id) if cache_entry is not None:
if data_list: data_list = cache_entry.getValue()
md5sum, mime, data = data_list if data_list:
if md5sum != self.getContentMd5(): md5sum, mime, data = data_list
raise KeyError, 'Conversion cache key is compromised for %r' % cache_id if md5sum != self.getContentMd5():
return mime, data raise KeyError, 'Conversion cache key is compromised for %r' % cache_id
return mime, data
raise KeyError, 'Conversion cache key does not exists for %r' % cache_id raise KeyError, 'Conversion cache key does not exists for %r' % cache_id
security.declareProtected(Permissions.View, 'getConversionSize') security.declareProtected(Permissions.View, 'getConversionSize')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment