From e83b3536d0c93234b50d75b8702071a75528afb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Fri, 19 Nov 2010 11:06:22 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40409 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/Tool/MemcachedTool.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/product/ERP5Type/Tool/MemcachedTool.py b/product/ERP5Type/Tool/MemcachedTool.py index f6fea9a651..66f2f62826 100644 --- a/product/ERP5Type/Tool/MemcachedTool.py +++ b/product/ERP5Type/Tool/MemcachedTool.py @@ -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: -- 2.30.9