[Erp5-report] r40409 jerome - /erp5/trunk/products/ERP5Type/Tool/MemcachedTool.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Nov 19 12:06:24 CET 2010


Author: jerome
Date: Fri Nov 19 12:06:22 2010
New Revision: 40409

URL: http://svn.erp5.org?rev=40409&view=rev
Log:
According to memcached protocol, if expiration is greater than 30 days, it is
not expressed in seconds but as a timestamp. Expirations in ERP5 are always
expressed in seconds, so we have to treat differently expiration greater than
30 days.


Modified:
    erp5/trunk/products/ERP5Type/Tool/MemcachedTool.py

Modified: erp5/trunk/products/ERP5Type/Tool/MemcachedTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Tool/MemcachedTool.py?rev=40409&r1=40408&r2=40409&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Tool/MemcachedTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Tool/MemcachedTool.py [utf8] Fri Nov 19 12:06:22 2010
@@ -27,6 +27,7 @@
 #
 ##############################################################################
 
+import time
 from threading import local
 from Products.ERP5Type.Tool.BaseTool import BaseTool
 from Products.ERP5Type import Permissions, _dtmldir
@@ -95,6 +96,8 @@ if memcache is not None:
       self.local_cache = {}
       self.scheduled_action_dict = {}
       self.server_list = server_list
+      # see "Expiration times" from memcached protocol docs
+      self.expiration_time_since_epoch = expiration_time > (60*60*24*30)
       self.expiration_time = expiration_time
       self.server_max_key_length = server_max_key_length
       self.server_max_value_length = server_max_value_length
@@ -126,6 +129,9 @@ if memcache is not None:
         would not be ignored.
       """
       try:
+        expiration_time = self.expiration_time
+        if self.expiration_time_since_epoch:
+          expiration_time += time.time()
         for key, value in self.local_cache.iteritems():
           if getattr(value, MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID, None):
             delattr(value, MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID)
@@ -133,13 +139,13 @@ if memcache is not None:
         for key, action in self.scheduled_action_dict.iteritems():
           if action is UPDATE_ACTION:
             succeed = self.memcached_connection.set(encodeKey(key),
-                                                    self.local_cache[key], 
-                                                    self.expiration_time)
+                                                    self.local_cache[key],
+                                                    expiration_time)
             if not succeed:
               self._initialiseConnection()
               succeed = self.memcached_connection.set(encodeKey(key),
-                                                      self.local_cache[key], 
-                                                      self.expiration_time)
+                                                      self.local_cache[key],
+                                                      expiration_time)
               if not succeed:
                 LOG('MemcacheTool', 0, 'set command to memcached server (%r) failed' % (self.server_list,))
           elif action is DELETE_ACTION:




More information about the Erp5-report mailing list