Commit 5a0aa17a authored by Nicolas Delaby's avatar Nicolas Delaby

Add a prefix to build the key of DistributedRamCache with

 - erp5_site_global_id: a site property.
 - cache_plugin_path: path of the cache plugin itself.
This is usefull to share the same memcached server for multiple instances.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28482 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 42b53658
...@@ -60,6 +60,7 @@ class DistributedRamCache(BaseCache): ...@@ -60,6 +60,7 @@ class DistributedRamCache(BaseCache):
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)
self._key_prefix = params.get('key_prefix', '') self._key_prefix = params.get('key_prefix', '')
self._cache_plugin_path = params.get('cache_plugin_path')
BaseCache.__init__(self) BaseCache.__init__(self)
def initCacheStorage(self): def initCacheStorage(self):
...@@ -91,7 +92,8 @@ class DistributedRamCache(BaseCache): ...@@ -91,7 +92,8 @@ class DistributedRamCache(BaseCache):
def checkAndFixCacheId(self, cache_id, scope): def checkAndFixCacheId(self, cache_id, scope):
## memcached doesn't support namespaces (cache scopes) so to "emmulate" ## memcached doesn't support namespaces (cache scopes) so to "emmulate"
## such behaviour when constructing cache_id we add scope in front ## such behaviour when constructing cache_id we add scope in front
cache_id = "%s%s.%s" % (self._key_prefix, scope, cache_id) cache_id = "%s%s%s%s" % (self._key_prefix, self._cache_plugin_path,
scope, cache_id)
if self._server_max_key_length != 0: if self._server_max_key_length != 0:
## memcached will fail to store cache_id longer than MEMCACHED_SERVER_MAX_KEY_LENGTH. ## memcached will fail to store cache_id longer than MEMCACHED_SERVER_MAX_KEY_LENGTH.
return cache_id[:self._server_max_key_length] return cache_id[:self._server_max_key_length]
......
...@@ -91,6 +91,8 @@ class CacheTool(BaseTool): ...@@ -91,6 +91,8 @@ class CacheTool(BaseTool):
'server': server, 'server': server,
'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(),
'cache_plugin_path': cp.getPath(),
'key_prefix': getattr(self, 'erp5_site_global_id', '')
} }
cache_obj = DistributedRamCache(init_dict) cache_obj = DistributedRamCache(init_dict)
if cache_obj is not None: if cache_obj is not None:
......
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