parent
42fef29446
commit
cf7ddc5765
|
@ -27,10 +27,7 @@ class LocMemCache(BaseCache):
|
|||
def add(self, key, value, timeout=DEFAULT_TIMEOUT, version=None):
|
||||
key = self.make_key(key, version=version)
|
||||
self.validate_key(key)
|
||||
try:
|
||||
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
|
||||
except pickle.PickleError:
|
||||
return False
|
||||
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
|
||||
with self._lock.writer():
|
||||
exp = self._expire_info.get(key)
|
||||
if exp is None or exp <= time.time():
|
||||
|
@ -69,13 +66,9 @@ class LocMemCache(BaseCache):
|
|||
def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None):
|
||||
key = self.make_key(key, version=version)
|
||||
self.validate_key(key)
|
||||
try:
|
||||
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
|
||||
except pickle.PickleError:
|
||||
pass
|
||||
else:
|
||||
with self._lock.writer():
|
||||
self._set(key, pickled, timeout)
|
||||
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
|
||||
with self._lock.writer():
|
||||
self._set(key, pickled, timeout)
|
||||
|
||||
def incr(self, key, delta=1, version=None):
|
||||
value = self.get(key, version=version)
|
||||
|
@ -83,13 +76,9 @@ class LocMemCache(BaseCache):
|
|||
raise ValueError("Key '%s' not found" % key)
|
||||
new_value = value + delta
|
||||
key = self.make_key(key, version=version)
|
||||
try:
|
||||
pickled = pickle.dumps(new_value, pickle.HIGHEST_PROTOCOL)
|
||||
except pickle.PickleError:
|
||||
pass
|
||||
else:
|
||||
with self._lock.writer():
|
||||
self._cache[key] = pickled
|
||||
pickled = pickle.dumps(new_value, pickle.HIGHEST_PROTOCOL)
|
||||
with self._lock.writer():
|
||||
self._cache[key] = pickled
|
||||
return new_value
|
||||
|
||||
def has_key(self, key, version=None):
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import pickle
|
||||
import re
|
||||
import shutil
|
||||
import tempfile
|
||||
|
@ -32,6 +31,7 @@ from django.utils import timezone
|
|||
from django.utils import translation
|
||||
from django.utils.cache import (patch_vary_headers, get_cache_key,
|
||||
learn_cache_key, patch_cache_control, patch_response_headers)
|
||||
from django.utils.six.moves import cPickle as pickle
|
||||
from django.utils.encoding import force_text
|
||||
from django.views.decorators.cache import cache_page
|
||||
|
||||
|
|
Loading…
Reference in New Issue