django 的BaseMemcachedCache线程安全问题

注意,django.core.cache.backends.memcached import BaseMemcachedCache 的_cache存在线程安全问题,请看他的代码:
mc_client
class MemcachedCache(BaseMemcachedCache):
    "An implementation of a cache binding using python-memcached"
    def __init__(self, server, params):
        
        super(MemcachedCache, self).__init__(server, params,
                                             library=memcache,
                                             value_not_found_exception=ValueError)
    @property
    def _cache(self):
        """
        Implements transparent thread-safe access to a memcached client.
        """
        global mc_client
        if mc_client is None:
            mc_client = self._lib.Client(self._servers)

        return mc_client


self._lib.Client(self._servers)可能被初始化多次,因为没有加锁。

猜你喜欢

转载自san-yun.iteye.com/blog/1702523