Merge branch 'ticket_20613' of https://github.com/ersran9/django into t20613
This commit is contained in:
commit
126250a4c4
|
@ -26,28 +26,31 @@ class LocMemCache(BaseCache):
|
||||||
def add(self, key, value, timeout=DEFAULT_TIMEOUT, version=None):
|
def add(self, key, value, timeout=DEFAULT_TIMEOUT, version=None):
|
||||||
key = self.make_key(key, version=version)
|
key = self.make_key(key, version=version)
|
||||||
self.validate_key(key)
|
self.validate_key(key)
|
||||||
|
try:
|
||||||
|
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
|
||||||
|
except pickle.PickleError:
|
||||||
|
return False
|
||||||
with self._lock.writer():
|
with self._lock.writer():
|
||||||
exp = self._expire_info.get(key)
|
exp = self._expire_info.get(key)
|
||||||
if exp is None or exp <= time.time():
|
if exp is None or exp <= time.time():
|
||||||
try:
|
self._set(key, pickled, timeout)
|
||||||
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
|
return True
|
||||||
self._set(key, pickled, timeout)
|
|
||||||
return True
|
|
||||||
except pickle.PickleError:
|
|
||||||
pass
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get(self, key, default=None, version=None):
|
def get(self, key, default=None, version=None):
|
||||||
key = self.make_key(key, version=version)
|
key = self.make_key(key, version=version)
|
||||||
self.validate_key(key)
|
self.validate_key(key)
|
||||||
|
pickled = None
|
||||||
with self._lock.reader():
|
with self._lock.reader():
|
||||||
exp = self._expire_info.get(key, 0)
|
exp = self._expire_info.get(key, 0)
|
||||||
if exp is None or exp > time.time():
|
if exp is None or exp > time.time():
|
||||||
try:
|
pickled = self._cache[key]
|
||||||
pickled = self._cache[key]
|
try:
|
||||||
return pickle.loads(pickled)
|
if pickled is not None:
|
||||||
except pickle.PickleError:
|
return pickle.loads(pickled)
|
||||||
return default
|
except pickle.PickleError:
|
||||||
|
return default
|
||||||
|
|
||||||
with self._lock.writer():
|
with self._lock.writer():
|
||||||
try:
|
try:
|
||||||
del self._cache[key]
|
del self._cache[key]
|
||||||
|
@ -68,25 +71,25 @@ class LocMemCache(BaseCache):
|
||||||
def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None):
|
def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None):
|
||||||
key = self.make_key(key, version=version)
|
key = self.make_key(key, version=version)
|
||||||
self.validate_key(key)
|
self.validate_key(key)
|
||||||
with self._lock.writer():
|
try:
|
||||||
try:
|
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
|
||||||
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
|
with self._lock.writer():
|
||||||
self._set(key, pickled, timeout)
|
self._set(key, pickled, timeout)
|
||||||
except pickle.PickleError:
|
except pickle.PickleError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def incr(self, key, delta=1, version=None):
|
def incr(self, key, delta=1, version=None):
|
||||||
value = self.get(key, version=version)
|
value = self.get(key, version=version)
|
||||||
if value is None:
|
if value is None:
|
||||||
raise ValueError("Key '%s' not found" % key)
|
raise ValueError("Key '%s' not found" % key)
|
||||||
new_value = value + delta
|
new_value = value + delta
|
||||||
key = self.make_key(key, version=version)
|
key = self.make_key(key, version=version)
|
||||||
with self._lock.writer():
|
try:
|
||||||
try:
|
pickled = pickle.dumps(new_value, pickle.HIGHEST_PROTOCOL)
|
||||||
pickled = pickle.dumps(new_value, pickle.HIGHEST_PROTOCOL)
|
with self._lock.writer():
|
||||||
self._cache[key] = pickled
|
self._cache[key] = pickled
|
||||||
except pickle.PickleError:
|
except pickle.PickleError:
|
||||||
pass
|
pass
|
||||||
return new_value
|
return new_value
|
||||||
|
|
||||||
def has_key(self, key, version=None):
|
def has_key(self, key, version=None):
|
||||||
|
|
Loading…
Reference in New Issue