[Erp5-report] r31662 jp - /erp5/trunk/products/ERP5/mixin/cached_convertable.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Jan 8 09:28:00 CET 2010


Author: jp
Date: Fri Jan  8 09:27:57 2010
New Revision: 31662

URL: http://svn.erp5.org?rev=31662&view=rev
Log:
Made the key more explicit with shared code througth a private method. Use UID instead of path. (will be replaced by uuid generated some day)

Modified:
    erp5/trunk/products/ERP5/mixin/cached_convertable.py

Modified: erp5/trunk/products/ERP5/mixin/cached_convertable.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/mixin/cached_convertable.py?rev=31662&r1=31661&r2=31662&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/mixin/cached_convertable.py [utf8] (original)
+++ erp5/trunk/products/ERP5/mixin/cached_convertable.py [utf8] Fri Jan  8 09:27:57 2010
@@ -78,6 +78,17 @@
       cache_tool.updateCache()
     return cache_tool.getRamCacheRoot().get(cache_factory_name)
 
+  def _getCacheKey(self):
+    """
+    Returns the key to use for the cache entries. For now,
+    use the object uid. 
+
+    TODO: XXX-JPS use instance in the future
+    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):
     """
@@ -86,7 +97,7 @@
       self.temp_conversion_data = {}
       return
     for cache_plugin in self._getCacheFactory().getCachePluginList():
-      cache_plugin.delete(self.getPath(), DEFAULT_CACHE_SCOPE)
+      cache_plugin.delete(self._getCacheKey(), DEFAULT_CACHE_SCOPE)
 
   security.declareProtected(Permissions.View, 'hasConversion')
   def hasConversion(self, **kw):
@@ -129,12 +140,12 @@
     if data is not None:
       for cache_plugin in cache_factory.getCachePluginList():
         try:
-          cache_entry = cache_plugin.get(self.getPath(), DEFAULT_CACHE_SCOPE)
+          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.getPath(), DEFAULT_CACHE_SCOPE,
+        cache_plugin.set(self._getCacheKey(), DEFAULT_CACHE_SCOPE,
                          cache_dict, calculation_time=calculation_time,
                          cache_duration=cache_duration)
 
@@ -146,8 +157,7 @@
     if self.isTempObject():
       return getattr(aq_base(self), 'temp_conversion_data', {})[cache_id]
     for cache_plugin in self._getCacheFactory().getCachePluginList():
-      document_path = getattr(aq_base(self), 'original_path', self.getPath())
-      cache_entry = cache_plugin.get(document_path, DEFAULT_CACHE_SCOPE)
+      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
@@ -175,6 +185,11 @@
   security.declareProtected(Permissions.ModifyPortalContent, 'updateContentMd5')
   def updateContentMd5(self):
     """Update md5 checksum from the original file
+    
+    XXX-JPS - this method is not part of any interfacce.
+              should it be public or private. It is called
+              by some interaction workflow already. Is
+              it general or related to caching only ?
     """
     data = self.getData()
-    self._setContentMd5(md5.new(data).hexdigest()) #reindex is useless
+    self._setContentMd5(md5.new(data).hexdigest()) # Reindex is useless




More information about the Erp5-report mailing list