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):
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:
......
......@@ -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' ,
},
)
......@@ -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', '')
......
......@@ -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
......
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