Commit 828a7dd7 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

if memcached connection is lost, recreate the connection and try once more.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38772 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0a04a94e
......@@ -94,14 +94,19 @@ if memcache is not None:
"""
self.local_cache = {}
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:
init_dict['server_max_value_length'] = server_max_value_length
self.memcached_connection = memcache.Client(server_list, **init_dict)
self.server_max_key_length = server_max_key_length
self.server_max_value_length = server_max_value_length
self._initialiseConnection()
def _initialiseConnection(self):
init_dict = {}
if self.server_max_key_length is not MARKER:
init_dict['server_max_key_length'] = self.server_max_key_length
if self.server_max_value_length is not MARKER:
init_dict['server_max_value_length'] = self.server_max_value_length
self.memcached_connection = memcache.Client(self.server_list, **init_dict)
def __del__(self):
"""
......@@ -123,12 +128,20 @@ 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],
self.expiration_time)
if not succeed:
self._initialiseConnection()
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:
succeed = self.memcached_connection.delete(encodeKey(key), 0)
if not succeed:
self._initialiseConnection()
succeed = self.memcached_connection.delete(encodeKey(key), 0)
if not succeed:
LOG('MemcacheTool', 0, 'delete command to memcached server (%r) failed' % (self.server_list,))
......@@ -154,6 +167,9 @@ if memcache is not None:
encoded_key = encodeKey(key)
result = self.local_cache.get(key, MARKER)
if result is MARKER:
result = self.memcached_connection.get(encoded_key)
if result is None:
self._initialiseConnection()
result = self.memcached_connection.get(encoded_key)
if result is None:
raise KeyError, 'Key %s (was %s) not found.' % (encoded_key, key)
......
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