def _cache(self, key, data):
current_lock = self._lock_value()
with self.client_pool.reserve() as client:
while True:
value, cid = client.gets(key)
# If there is a lock value in Memcache that is
# different from our own we have to bail.
if value and value.startswith(self._lock_prefix) and value != current_lock:
return
# If there isn't a value at all, we have to add one
# and try again.
if cid is None:
client.add(key, current_lock, self._lock_timeout)
continue
try:
return client.cas(key, data, cid, self._item_timeout)
# There is a small chance that between the `gets` and
# "now" the key will have been deleted by a concurrent
# process, so we account for that possibility here.
except pylibmc.NotFound: # pragma: no cover
return
评论列表
文章目录