Commit ce55639f authored by Nicolas Delaby's avatar Nicolas Delaby

Space cleanup


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32367 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8418f6e4
...@@ -69,12 +69,12 @@ if memcache is not None: ...@@ -69,12 +69,12 @@ if memcache is not None:
available). available).
Uses transactions to only update memcached at commit time. Uses transactions to only update memcached at commit time.
No conflict generation/resolution : last edit wins. No conflict generation/resolution : last edit wins.
TODO: TODO:
- prove that concurency handling in event queuing is not needed - prove that concurency handling in event queuing is not needed
- 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',), server_max_key_length=MARKER,
server_max_value_length=MARKER): server_max_value_length=MARKER):
""" """
...@@ -133,14 +133,14 @@ if memcache is not None: ...@@ -133,14 +133,14 @@ if memcache is not None:
LOG('MemcachedDict', 0, 'An exception occured during _finish : %s' % (traceback.format_exc(), )) LOG('MemcachedDict', 0, 'An exception occured during _finish : %s' % (traceback.format_exc(), ))
self.scheduled_action_dict.clear() self.scheduled_action_dict.clear()
self.local_cache.clear() self.local_cache.clear()
def _abort(self, *ignored): def _abort(self, *ignored):
""" """
Cleanup the action dict and invalidate local cache. Cleanup the action dict and invalidate local cache.
""" """
self.local_cache.clear() self.local_cache.clear()
self.scheduled_action_dict.clear() self.scheduled_action_dict.clear()
def __getitem__(self, key): def __getitem__(self, key):
""" """
Get an item from local cache, otherwise from memcached. Get an item from local cache, otherwise from memcached.
...@@ -156,7 +156,7 @@ if memcache is not None: ...@@ -156,7 +156,7 @@ if memcache is not None:
raise KeyError, 'Key %s (was %s) not found.' % (encoded_key, key) raise KeyError, 'Key %s (was %s) not found.' % (encoded_key, key)
self.local_cache[key] = result self.local_cache[key] = result
return result return result
def __setitem__(self, key, value): def __setitem__(self, key, value):
""" """
Set an item to local cache and schedule update of memcached. Set an item to local cache and schedule update of memcached.
...@@ -164,7 +164,7 @@ if memcache is not None: ...@@ -164,7 +164,7 @@ if memcache is not None:
self._register() self._register()
self.scheduled_action_dict[key] = UPDATE_ACTION self.scheduled_action_dict[key] = UPDATE_ACTION
self.local_cache[key] = value self.local_cache[key] = value
def __delitem__(self, key): def __delitem__(self, key):
""" """
Schedule key for deletion in memcached. Schedule key for deletion in memcached.
...@@ -175,13 +175,13 @@ if memcache is not None: ...@@ -175,13 +175,13 @@ if memcache is not None:
self._register() self._register()
self.scheduled_action_dict[key] = DELETE_ACTION self.scheduled_action_dict[key] = DELETE_ACTION
self.local_cache[key] = None self.local_cache[key] = None
def set(self, key, value): def set(self, key, value):
""" """
Set an item to local cache and schedule update of memcached. Set an item to local cache and schedule update of memcached.
""" """
return self.__setitem__(key, value) return self.__setitem__(key, value)
def get(self, key, default=None): def get(self, key, default=None):
""" """
Get an item from local cache, otherwise from memcached. Get an item from local cache, otherwise from memcached.
...@@ -198,11 +198,11 @@ if memcache is not None: ...@@ -198,11 +198,11 @@ if memcache is not None:
Class to make possible for multiple "users" to store data in the same Class to make possible for multiple "users" to store data in the same
dictionary without risking to overwrite other's data. dictionary without risking to overwrite other's data.
Each "user" of the dictionary must get an instance of this class. Each "user" of the dictionary must get an instance of this class.
TODO: TODO:
- handle persistence ? - handle persistence ?
""" """
def __init__(self, dictionary, prefix): def __init__(self, dictionary, prefix):
""" """
dictionary dictionary
...@@ -212,7 +212,7 @@ if memcache is not None: ...@@ -212,7 +212,7 @@ if memcache is not None:
""" """
self._dictionary = dictionary self._dictionary = dictionary
self.prefix = prefix self.prefix = prefix
def _prefixKey(self, key): def _prefixKey(self, key):
""" """
Prefix key with self.prefix . Prefix key with self.prefix .
...@@ -220,44 +220,44 @@ if memcache is not None: ...@@ -220,44 +220,44 @@ if memcache is not None:
if not isinstance(key, basestring): if not isinstance(key, basestring):
raise TypeError, 'Key %s is not a string. Only strings are supported as key in SharedDict' % (repr(key), ) raise TypeError, 'Key %s is not a string. Only strings are supported as key in SharedDict' % (repr(key), )
return '%s_%s' % (self.prefix, key) return '%s_%s' % (self.prefix, key)
def __getitem__(self, key): def __getitem__(self, key):
""" """
Get item from memcached. Get item from memcached.
""" """
return self._dictionary.__getitem__(self._prefixKey(key)) return self._dictionary.__getitem__(self._prefixKey(key))
def __setitem__(self, key, value): def __setitem__(self, key, value):
""" """
Put item in memcached. Put item in memcached.
""" """
self._dictionary.__setitem__(self._prefixKey(key), value) self._dictionary.__setitem__(self._prefixKey(key), value)
def __delitem__(self, key): def __delitem__(self, key):
""" """
Delete item from memcached. Delete item from memcached.
""" """
self._dictionary.__delitem__(self._prefixKey(key)) self._dictionary.__delitem__(self._prefixKey(key))
# These are the method names called by zope # These are the method names called by zope
__guarded_setitem__ = __setitem__ __guarded_setitem__ = __setitem__
__guarded_getitem__ = __getitem__ __guarded_getitem__ = __getitem__
__guarded_delitem__ = __delitem__ __guarded_delitem__ = __delitem__
def get(self, key, default=None): def get(self, key, default=None):
""" """
Get item from memcached. Get item from memcached.
""" """
return self._dictionary.get(self._prefixKey(key), default) return self._dictionary.get(self._prefixKey(key), default)
def set(self, key, value): def set(self, key, value):
""" """
Put item in memcached. Put item in memcached.
""" """
self._dictionary.set(self._prefixKey(key), value) self._dictionary.set(self._prefixKey(key), value)
allow_class(SharedDict) allow_class(SharedDict)
class MemcachedTool(BaseTool): class MemcachedTool(BaseTool):
""" """
Memcached interface available as a tool. Memcached interface available as a tool.
......
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