mirror of https://github.com/django/django.git
parent
42fef29446
commit
cf7ddc5765
|
@ -27,10 +27,7 @@ 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)
|
||||||
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():
|
||||||
|
@ -69,13 +66,9 @@ 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)
|
||||||
try:
|
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
|
||||||
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
|
with self._lock.writer():
|
||||||
except pickle.PickleError:
|
self._set(key, pickled, timeout)
|
||||||
pass
|
|
||||||
else:
|
|
||||||
with self._lock.writer():
|
|
||||||
self._set(key, pickled, timeout)
|
|
||||||
|
|
||||||
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)
|
||||||
|
@ -83,13 +76,9 @@ class LocMemCache(BaseCache):
|
||||||
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)
|
||||||
try:
|
pickled = pickle.dumps(new_value, pickle.HIGHEST_PROTOCOL)
|
||||||
pickled = pickle.dumps(new_value, pickle.HIGHEST_PROTOCOL)
|
with self._lock.writer():
|
||||||
except pickle.PickleError:
|
self._cache[key] = pickled
|
||||||
pass
|
|
||||||
else:
|
|
||||||
with self._lock.writer():
|
|
||||||
self._cache[key] = pickled
|
|
||||||
return new_value
|
return new_value
|
||||||
|
|
||||||
def has_key(self, key, version=None):
|
def has_key(self, key, version=None):
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pickle
|
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -32,6 +31,7 @@ from django.utils import timezone
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
from django.utils.cache import (patch_vary_headers, get_cache_key,
|
from django.utils.cache import (patch_vary_headers, get_cache_key,
|
||||||
learn_cache_key, patch_cache_control, patch_response_headers)
|
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.utils.encoding import force_text
|
||||||
from django.views.decorators.cache import cache_page
|
from django.views.decorators.cache import cache_page
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue