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):
getcontentlength = get_size
def _setFile(self, data, precondition=None):
self.clearConversionCache()
CMFFile._edit(self, precondition=precondition, file=data)
security.declareProtected(Permissions.ModifyPortalContent,'setFile')
......@@ -170,7 +169,6 @@ class File(Document, CMFFile, CachedConvertableMixin):
security.declareProtected(Permissions.ModifyPortalContent,'PUT')
def PUT(self, REQUEST, RESPONSE):
self.clearConversionCache()
CMFFile.PUT(self, REQUEST, RESPONSE)
# DAV Support
......
......@@ -125,13 +125,6 @@ class TextDocument(Document, TextContent):
security.declareProtected( Permissions.ModifyPortalContent, '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
security.declareProtected(Permissions.View, 'index_html')
def index_html(self, REQUEST, RESPONSE, format=None, **kw):
......
......@@ -233,11 +233,6 @@ class IDocument(Interface):
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):
"""Return a boolean if conversion is cached
"""
......
......@@ -87,17 +87,7 @@ class CachedConvertableMixin:
http://pypi.python.org/pypi/uuid/ to generate
a uuid stored as private property.
"""
return aq_base(self).getUid()
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)
return '%s:%s' % (aq_base(self).getUid(), self.getRevision())
security.declareProtected(Permissions.View, 'hasConversion')
def hasConversion(self, **kw):
......@@ -129,7 +119,7 @@ class CachedConvertableMixin:
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 getattr(aq_base(self), 'temp_conversion_data', None) is None:
self.temp_conversion_data = {}
......@@ -139,31 +129,27 @@ class CachedConvertableMixin:
cache_duration = cache_factory.cache_duration
if data is not None:
for cache_plugin in cache_factory.getCachePluginList():
try:
cache_entry = cache_plugin.get(self._getCacheKey(), DEFAULT_CACHE_SCOPE)
cache_dict = cache_entry.getValue()
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_plugin.set(cache_id, DEFAULT_CACHE_SCOPE,
(self.getContentMd5(), mime, aq_base(data)),
calculation_time=calculation_time,
cache_duration=cache_duration)
security.declareProtected(Permissions.View, 'getConversion')
def getConversion(self, **kw):
"""
"""
cache_id = self.generateCacheId(**kw)
cache_id = '%s%s' % (self._getCacheKey(), self.generateCacheId(**kw))
if self.isTempObject():
return getattr(aq_base(self), 'temp_conversion_data', {})[cache_id]
for cache_plugin in self._getCacheFactory().getCachePluginList():
cache_entry = cache_plugin.get(self._getCacheKey(), DEFAULT_CACHE_SCOPE)
data_list = cache_entry.getValue().get(cache_id)
if data_list:
md5sum, mime, data = data_list
if md5sum != self.getContentMd5():
raise KeyError, 'Conversion cache key is compromised for %r' % cache_id
return mime, data
cache_entry = cache_plugin.get(cache_id, DEFAULT_CACHE_SCOPE)
if cache_entry is not None:
data_list = cache_entry.getValue()
if data_list:
md5sum, mime, data = data_list
if md5sum != self.getContentMd5():
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
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