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