Commit 9209e9f7 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

Use thread local variable instead of volatile variable to keep memcached dict,...

Use thread local variable instead of volatile variable to keep memcached dict, otherwise it sometimes disappears and causes many connections to memcached.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24285 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2cf6cf87
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
# #
############################################################################## ##############################################################################
from threading import local
from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions, _dtmldir from Products.ERP5Type import Permissions, _dtmldir
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
...@@ -62,6 +63,8 @@ if memcache is not None: ...@@ -62,6 +63,8 @@ if memcache is not None:
DELETE_ACTION = 'delete' DELETE_ACTION = 'delete'
MEMCACHED_MINIMUM_KEY_CHAR_ORD = ord(' ') MEMCACHED_MINIMUM_KEY_CHAR_ORD = ord(' ')
memcached_dict_pool = local()
class MemcachedDict(TM): class MemcachedDict(TM):
""" """
Present memcached similarly to a dictionary (not all method are Present memcached similarly to a dictionary (not all method are
...@@ -266,10 +269,11 @@ if memcache is not None: ...@@ -266,10 +269,11 @@ if memcache is not None:
Return used memcached dict. Return used memcached dict.
Create it if does not exist. Create it if does not exist.
""" """
dictionary = getattr(self, '_v_memcached_dict', None) try:
if dictionary is None: dictionary = memcached_dict_pool.memcached_dict
except AttributeError:
dictionary = MemcachedDict(self.getServerAddressList()) dictionary = MemcachedDict(self.getServerAddressList())
self._v_memcached_dict = dictionary memcached_dict_pool.memcached_dict = dictionary
return dictionary return dictionary
security.declareProtected(Permissions.AccessContentsInformation, 'getMemcachedDict') security.declareProtected(Permissions.AccessContentsInformation, 'getMemcachedDict')
...@@ -290,8 +294,6 @@ if memcache is not None: ...@@ -290,8 +294,6 @@ if memcache is not None:
Set a memcached server address. Set a memcached server address.
""" """
self.setServerAddressList([value, ]) self.setServerAddressList([value, ])
self.server_address_list = [value, ]
self._v_memcached_dict = None
security.declareProtected(Permissions.AccessContentsInformation, 'getServerAddress') security.declareProtected(Permissions.AccessContentsInformation, 'getServerAddress')
def getServerAddress(self): def getServerAddress(self):
...@@ -320,7 +322,10 @@ if memcache is not None: ...@@ -320,7 +322,10 @@ if memcache is not None:
to reconnect to memcached. to reconnect to memcached.
""" """
self.server_address_list = value self.server_address_list = value
self._v_memcached_dict = None try:
del(memcached_dict_pool.memcached_dict)
except AttributeError:
pass
else: else:
# Placeholder memcache tool # Placeholder memcache 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