Commit 6f13d778 authored by Nicolas Delaby's avatar Nicolas Delaby

Add expiration_time property on MemcachedPlugin to support expiration feature

of memcached protocol.
Extend MemcahedTool and MemcachedDict API to handle expiration_time parameter.
Note that CacheTool implement this feature through CacheEntry API.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34779 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8cc7d984
...@@ -57,6 +57,7 @@ class DistributedRamCache(BaseCache): ...@@ -57,6 +57,7 @@ class DistributedRamCache(BaseCache):
def __init__(self, params={}): def __init__(self, params={}):
self._servers = params.get('server', '') 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_key_length = params.get('server_max_key_length', 250)
self._server_max_value_length = params.get('server_max_value_length', 1024*1024) self._server_max_value_length = params.get('server_max_value_length', 1024*1024)
self._debug_level = params.get('debug_level', 0) self._debug_level = params.get('debug_level', 0)
...@@ -71,7 +72,8 @@ class DistributedRamCache(BaseCache): ...@@ -71,7 +72,8 @@ class DistributedRamCache(BaseCache):
def _getMemcachedDict(self): def _getMemcachedDict(self):
"""return a threading safe MemcachedDict instance """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._server_max_value_length,
self._debug_level, self._key_prefix) self._debug_level, self._key_prefix)
try: try:
......
...@@ -44,5 +44,11 @@ class MemcachedPlugin: ...@@ -44,5 +44,11 @@ class MemcachedPlugin:
'default' : 1048576, 'default' : 1048576,
'mode' : 'w' , 'mode' : 'w' ,
}, },
{'id' : 'expiration_time',
'description' : 'Time to live of stored value (in second)',
'type' : 'int',
'default' : 0,
'mode' : 'w' ,
},
) )
...@@ -89,6 +89,7 @@ class CacheTool(BaseTool): ...@@ -89,6 +89,7 @@ class CacheTool(BaseTool):
server = memcached_plugin.getUrlString('') server = memcached_plugin.getUrlString('')
init_dict = { init_dict = {
'server': server, 'server': server,
'expiration_time': cf.getCacheDuration(),
'server_max_key_length': memcached_plugin.getServerMaxKeyLength(), 'server_max_key_length': memcached_plugin.getServerMaxKeyLength(),
'server_max_value_length': memcached_plugin.getServerMaxValueLength(), 'server_max_value_length': memcached_plugin.getServerMaxValueLength(),
'key_prefix': getattr(self, 'erp5_site_global_id', '') 'key_prefix': getattr(self, 'erp5_site_global_id', '')
......
...@@ -75,8 +75,8 @@ if memcache is not None: ...@@ -75,8 +75,8 @@ if memcache is not None:
- make picklable ? - make picklable ?
""" """
def __init__(self, server_list=('127.0.0.1:11211',), server_max_key_length=MARKER, def __init__(self, server_list=('127.0.0.1:11211',), expiration_time=0,
server_max_value_length=MARKER): server_max_key_length=MARKER, server_max_value_length=MARKER):
""" """
Initialise properties : Initialise properties :
memcached_connection memcached_connection
...@@ -96,6 +96,7 @@ if memcache is not None: ...@@ -96,6 +96,7 @@ if memcache is not None:
self.scheduled_action_dict = {} self.scheduled_action_dict = {}
init_dict = {} init_dict = {}
self.server_list = server_list self.server_list = server_list
self.expiration_time = expiration_time
if server_max_key_length is not MARKER: if server_max_key_length is not MARKER:
init_dict['server_max_key_length'] = server_max_key_length init_dict['server_max_key_length'] = server_max_key_length
if server_max_value_length is not MARKER: if server_max_value_length is not MARKER:
...@@ -122,7 +123,9 @@ if memcache is not None: ...@@ -122,7 +123,9 @@ if memcache is not None:
self.scheduled_action_dict[key] = UPDATE_ACTION self.scheduled_action_dict[key] = UPDATE_ACTION
for key, action in self.scheduled_action_dict.iteritems(): for key, action in self.scheduled_action_dict.iteritems():
if action is UPDATE_ACTION: 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: if not succeed:
LOG('MemcacheTool', 0, 'set command to memcached server (%r) failed' % (self.server_list,)) LOG('MemcacheTool', 0, 'set command to memcached server (%r) failed' % (self.server_list,))
elif action is DELETE_ACTION: elif action is DELETE_ACTION:
...@@ -289,6 +292,7 @@ if memcache is not None: ...@@ -289,6 +292,7 @@ if memcache is not None:
if memcached_plugin is None: if memcached_plugin is None:
raise ValueError, 'Memcached Plugin does not exists: %r' % (plugin_path,) raise ValueError, 'Memcached Plugin does not exists: %r' % (plugin_path,)
dictionary = MemcachedDict((memcached_plugin.getUrlString(''),), dictionary = MemcachedDict((memcached_plugin.getUrlString(''),),
expiration_time=memcached_plugin.getExpirationTime(),
server_max_key_length=memcached_plugin.getServerMaxKeyLength(), server_max_key_length=memcached_plugin.getServerMaxKeyLength(),
server_max_value_length=memcached_plugin.getServerMaxValueLength()) server_max_value_length=memcached_plugin.getServerMaxValueLength())
local_dict[plugin_path] = dictionary local_dict[plugin_path] = dictionary
......
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