注意,django.core.cache.backends.memcached import BaseMemcachedCache 的_cache存在线程安全问题,请看他的代码:
self._lib.Client(self._servers)可能被初始化多次,因为没有加锁。
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)可能被初始化多次,因为没有加锁。
本文分析了 Django 中使用 python-memcached 实现缓存时存在的线程安全问题,具体表现为 _cache 属性的初始化过程中未加锁可能导致多次初始化。

5069

被折叠的 条评论
为什么被折叠?



