diff --git a/product/ERP5Type/CachePlugins/DistributedRamCache.py b/product/ERP5Type/CachePlugins/DistributedRamCache.py index 3ba03b0efeb7a687d459b4e3b2b3fc6b51224053..c4a36d8e16cbf331c91ebf9b6296b4dbd08a8ec6 100644 --- a/product/ERP5Type/CachePlugins/DistributedRamCache.py +++ b/product/ERP5Type/CachePlugins/DistributedRamCache.py @@ -57,6 +57,7 @@ class DistributedRamCache(BaseCache): def __init__(self, params={}): self._servers = params.get('server', '') + self._expiration_time = params.get('expiration_time', 0) self._server_max_key_length = params.get('server_max_key_length', 250) self._server_max_value_length = params.get('server_max_value_length', 1024*1024) self._debug_level = params.get('debug_level', 0) @@ -71,7 +72,8 @@ class DistributedRamCache(BaseCache): def _getMemcachedDict(self): """return a threading safe MemcachedDict instance """ - configuration_key = (self._servers, self._server_max_key_length, + configuration_key = (self._servers, self._expiration_time, + self._server_max_key_length, self._server_max_value_length, self._debug_level, self._key_prefix) try: diff --git a/product/ERP5Type/PropertySheet/MemcachedPlugin.py b/product/ERP5Type/PropertySheet/MemcachedPlugin.py index 11750ec1774dcca18d98814db869c3f84eac1878..3658876be35820696358c9af63f925029ca8459e 100644 --- a/product/ERP5Type/PropertySheet/MemcachedPlugin.py +++ b/product/ERP5Type/PropertySheet/MemcachedPlugin.py @@ -44,5 +44,11 @@ class MemcachedPlugin: 'default' : 1048576, 'mode' : 'w' , }, + {'id' : 'expiration_time', + 'description' : 'Time to live of stored value (in second)', + 'type' : 'int', + 'default' : 0, + 'mode' : 'w' , + }, ) diff --git a/product/ERP5Type/Tool/CacheTool.py b/product/ERP5Type/Tool/CacheTool.py index d8dd5ac3c022312ed9362b21ef64a8e175c659b0..6ab8e55fc69809cebfc5855b0d306911188ca1d2 100644 --- a/product/ERP5Type/Tool/CacheTool.py +++ b/product/ERP5Type/Tool/CacheTool.py @@ -89,6 +89,7 @@ class CacheTool(BaseTool): server = memcached_plugin.getUrlString('') init_dict = { 'server': server, + 'expiration_time': cf.getCacheDuration(), 'server_max_key_length': memcached_plugin.getServerMaxKeyLength(), 'server_max_value_length': memcached_plugin.getServerMaxValueLength(), 'key_prefix': getattr(self, 'erp5_site_global_id', '') diff --git a/product/ERP5Type/Tool/MemcachedTool.py b/product/ERP5Type/Tool/MemcachedTool.py index b7b9bc710fea696fcf978268c320605eebc8dea5..b866ff37164b1ab5d8bd937afad60cbbff415c51 100644 --- a/product/ERP5Type/Tool/MemcachedTool.py +++ b/product/ERP5Type/Tool/MemcachedTool.py @@ -75,8 +75,8 @@ if memcache is not None: - make picklable ? """ - def __init__(self, server_list=('127.0.0.1:11211',), server_max_key_length=MARKER, - server_max_value_length=MARKER): + def __init__(self, server_list=('127.0.0.1:11211',), expiration_time=0, + server_max_key_length=MARKER, server_max_value_length=MARKER): """ Initialise properties : memcached_connection @@ -96,6 +96,7 @@ if memcache is not None: self.scheduled_action_dict = {} init_dict = {} self.server_list = server_list + self.expiration_time = expiration_time if server_max_key_length is not MARKER: init_dict['server_max_key_length'] = server_max_key_length if server_max_value_length is not MARKER: @@ -122,7 +123,9 @@ if memcache is not None: self.scheduled_action_dict[key] = UPDATE_ACTION 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], 0) + succeed = self.memcached_connection.set(encodeKey(key), + self.local_cache[key], + self.expiration_time) if not succeed: LOG('MemcacheTool', 0, 'set command to memcached server (%r) failed' % (self.server_list,)) elif action is DELETE_ACTION: @@ -289,6 +292,7 @@ if memcache is not None: if memcached_plugin is None: raise ValueError, 'Memcached Plugin does not exists: %r' % (plugin_path,) dictionary = MemcachedDict((memcached_plugin.getUrlString(''),), + expiration_time=memcached_plugin.getExpirationTime(), server_max_key_length=memcached_plugin.getServerMaxKeyLength(), server_max_value_length=memcached_plugin.getServerMaxValueLength()) local_dict[plugin_path] = dictionary