Commit d200dc21 authored by Nicolas Delaby's avatar Nicolas Delaby

return expected plugin with additionnal parameter

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27563 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fd530345
...@@ -262,10 +262,10 @@ if memcache is not None: ...@@ -262,10 +262,10 @@ if memcache is not None:
manage_options = ({'label': 'Configure', manage_options = ({'label': 'Configure',
'action': 'memcached_tool_configure', 'action': 'memcached_tool_configure',
},) + BaseTool.manage_options },) + BaseTool.manage_options
memcached_tool_configure = DTMLFile('memcached_tool_configure', _dtmldir) memcached_tool_configure = DTMLFile('memcached_tool_configure', _dtmldir)
def _getMemcachedDict(self): def _getMemcachedDict(self, plugin_path=None):
""" """
Return used memcached dict. Return used memcached dict.
Create it if does not exist. Create it if does not exist.
...@@ -273,65 +273,60 @@ if memcache is not None: ...@@ -273,65 +273,60 @@ if memcache is not None:
try: try:
dictionary = memcached_dict_pool.memcached_dict dictionary = memcached_dict_pool.memcached_dict
except AttributeError: except AttributeError:
dictionary = MemcachedDict(self.getServerAddressList()) dictionary = MemcachedDict(self.getServerAddressList(plugin_path=plugin_path))
memcached_dict_pool.memcached_dict = dictionary memcached_dict_pool.memcached_dict = dictionary
return dictionary return dictionary
security.declareProtected(Permissions.AccessContentsInformation, 'getMemcachedDict') security.declareProtected(Permissions.AccessContentsInformation, 'getMemcachedDict')
def getMemcachedDict(self, key_prefix): def getMemcachedDict(self, key_prefix, plugin_path=None):
""" """
Returns an object which can be used as a dict and which gets from/stores Returns an object which can be used as a dict and which gets from/stores
to memcached server. to memcached server.
key_prefix key_prefix
Mendatory argument allowing different tool users from sharing the same Mendatory argument allowing different tool users from sharing the same
dictionary key namespace. dictionary key namespace.
plugin_path
relative_url of dedicated Memcached Plugin
""" """
return SharedDict(dictionary=self._getMemcachedDict(), prefix=key_prefix) return SharedDict(dictionary=self._getMemcachedDict(plugin_path=plugin_path), prefix=key_prefix)
security.declareProtected(Permissions.ModifyPortalContent, 'setServerAddress') security.declareProtected(Permissions.ModifyPortalContent, 'setServerAddress')
def setServerAddress(self, value): def setServerAddress(self, value):
""" """
Set a memcached server address. Set a memcached server address.
""" """
self.setServerAddressList([value, ]) self.setServerAddressList([value, ])
security.declareProtected(Permissions.AccessContentsInformation, 'getServerAddress') security.declareProtected(Permissions.AccessContentsInformation, 'getServerAddress')
def getServerAddress(self): def getServerAddress(self):
""" """
Return server address. Return server address.
""" """
return self.getServerAddressList()[0] return self.getServerAddressList()[0]
def getServerAddressList(self): def getServerAddressList(self, plugin_path=None):
""" """
Get the list of memcached servers to use. Get the list of memcached servers to use.
Defaults to ['127.0.0.1:11211', ]. Defaults to ['127.0.0.1:11211', ].
""" """
server_address_list = [] server_address_list = []
for memcached_plugin in self.contentValues(portal_type='Memcached Plugin', sort_on='int_index'): for memcached_plugin in self.contentValues(portal_type='Memcached Plugin', sort_on='int_index'):
if plugin_path and memcached_plugin.getRelativeUrl() != plugin_path:
continue
server_address_list.append(memcached_plugin.getUrlString()) server_address_list.append(memcached_plugin.getUrlString())
return server_address_list return server_address_list
def setServerAddressList(self, value):
"""
Set the list of memcached servers to use.
Upon server address change, force next access to memcached dict to
reconnect to new ip.
This is safe in multi zope environment, since we modify self which is def manage_beforeDelete(self, document, container):
persistent. Then all zopes will have to reload this tool instance, and
loose their volatile properties in the process, which will force them
to reconnect to memcached.
"""
self.server_address_list = value
try: try:
del(memcached_dict_pool.memcached_dict) del(memcached_dict_pool.memcached_dict)
except AttributeError: except AttributeError:
pass pass
BaseTool.manage_beforeDelete(self, document, container)
else: else:
# Placeholder memcache tool # Placeholder memcache tool
class MemcachedTool(BaseTool): class MemcachedTool(BaseTool):
""" """
...@@ -358,6 +353,6 @@ else: ...@@ -358,6 +353,6 @@ else:
setServerAddress = failingMethod setServerAddress = failingMethod
getServerAddress = failingMethod getServerAddress = failingMethod
getServerAddressList = failingMethod getServerAddressList = failingMethod
setServerAddressList = failingMethod manage_beforeDelete = failingMethod
memcached_tool_configure = failingMethod memcached_tool_configure = failingMethod
getMemcachedDict = failingMethod getMemcachedDict = failingMethod
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