Commit 39ee3171 authored by Jérome Perrin's avatar Jérome Perrin

encode keys only once and only if necessary

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40410 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e83b3536
...@@ -137,22 +137,23 @@ if memcache is not None: ...@@ -137,22 +137,23 @@ if memcache is not None:
delattr(value, MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID) delattr(value, MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID)
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():
encoded_key = encodeKey(key)
if action is UPDATE_ACTION: if action is UPDATE_ACTION:
succeed = self.memcached_connection.set(encodeKey(key), succeed = self.memcached_connection.set(encoded_key,
self.local_cache[key], self.local_cache[key],
expiration_time) expiration_time)
if not succeed: if not succeed:
self._initialiseConnection() self._initialiseConnection()
succeed = self.memcached_connection.set(encodeKey(key), succeed = self.memcached_connection.set(encoded_key,
self.local_cache[key], self.local_cache[key],
expiration_time) 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:
succeed = self.memcached_connection.delete(encodeKey(key), 0) succeed = self.memcached_connection.delete(encoded_key, 0)
if not succeed: if not succeed:
self._initialiseConnection() self._initialiseConnection()
succeed = self.memcached_connection.delete(encodeKey(key), 0) succeed = self.memcached_connection.delete(encoded_key, 0)
if not succeed: if not succeed:
LOG('MemcacheTool', 0, 'delete command to memcached server (%r) failed' % (self.server_list,)) LOG('MemcacheTool', 0, 'delete command to memcached server (%r) failed' % (self.server_list,))
except: except:
...@@ -176,9 +177,9 @@ if memcache is not None: ...@@ -176,9 +177,9 @@ if memcache is not None:
self._register() self._register()
if self.scheduled_action_dict.get(key) == DELETE_ACTION: if self.scheduled_action_dict.get(key) == DELETE_ACTION:
raise KeyError raise KeyError
encoded_key = encodeKey(key)
result = self.local_cache.get(key, MARKER) result = self.local_cache.get(key, MARKER)
if result is MARKER: if result is MARKER:
encoded_key = encodeKey(key)
try: try:
result = self.memcached_connection.get(encoded_key) result = self.memcached_connection.get(encoded_key)
except memcache.Client.MemcachedConnectionError: except memcache.Client.MemcachedConnectionError:
......
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