mirror of
https://github.com/django/django.git
synced 2025-04-26 02:04:38 +00:00
Fixed #599 -- locmem cache now uses deepcopy() to prevent aliasing. Thanks, Hugo
git-svn-id: http://code.djangoproject.com/svn/django/trunk@821 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f258a8fce2
commit
b4e2d12b1f
@ -72,7 +72,6 @@ class InvalidCacheBackendError(Exception):
|
|||||||
################################
|
################################
|
||||||
|
|
||||||
class _Cache:
|
class _Cache:
|
||||||
|
|
||||||
def __init__(self, params):
|
def __init__(self, params):
|
||||||
timeout = params.get('timeout', 300)
|
timeout = params.get('timeout', 300)
|
||||||
try:
|
try:
|
||||||
@ -132,8 +131,7 @@ except ImportError:
|
|||||||
_MemcachedCache = None
|
_MemcachedCache = None
|
||||||
else:
|
else:
|
||||||
class _MemcachedCache(_Cache):
|
class _MemcachedCache(_Cache):
|
||||||
"""Memcached cache backend."""
|
"Memcached cache backend."
|
||||||
|
|
||||||
def __init__(self, server, params):
|
def __init__(self, server, params):
|
||||||
_Cache.__init__(self, params)
|
_Cache.__init__(self, params)
|
||||||
self._cache = memcache.Client([server])
|
self._cache = memcache.Client([server])
|
||||||
@ -161,8 +159,7 @@ else:
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
class _SimpleCache(_Cache):
|
class _SimpleCache(_Cache):
|
||||||
"""Simple single-process in-memory cache"""
|
"Simple single-process in-memory cache."
|
||||||
|
|
||||||
def __init__(self, host, params):
|
def __init__(self, host, params):
|
||||||
_Cache.__init__(self, params)
|
_Cache.__init__(self, params)
|
||||||
self._cache = {}
|
self._cache = {}
|
||||||
@ -230,11 +227,11 @@ try:
|
|||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import pickle
|
import pickle
|
||||||
|
import copy
|
||||||
from django.utils.synch import RWLock
|
from django.utils.synch import RWLock
|
||||||
|
|
||||||
class _LocMemCache(_SimpleCache):
|
class _LocMemCache(_SimpleCache):
|
||||||
"""Thread-safe in-memory cache"""
|
"Thread-safe in-memory cache."
|
||||||
|
|
||||||
def __init__(self, host, params):
|
def __init__(self, host, params):
|
||||||
_SimpleCache.__init__(self, host, params)
|
_SimpleCache.__init__(self, host, params)
|
||||||
self._lock = RWLock()
|
self._lock = RWLock()
|
||||||
@ -250,7 +247,7 @@ class _LocMemCache(_SimpleCache):
|
|||||||
elif exp < now:
|
elif exp < now:
|
||||||
should_delete = True
|
should_delete = True
|
||||||
else:
|
else:
|
||||||
return self._cache[key]
|
return copy.deepcopy(self._cache[key])
|
||||||
finally:
|
finally:
|
||||||
self._lock.reader_leaves()
|
self._lock.reader_leaves()
|
||||||
if should_delete:
|
if should_delete:
|
||||||
@ -284,8 +281,7 @@ import os
|
|||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
class _FileCache(_SimpleCache):
|
class _FileCache(_SimpleCache):
|
||||||
"""File-based cache"""
|
"File-based cache."
|
||||||
|
|
||||||
def __init__(self, dir, params):
|
def __init__(self, dir, params):
|
||||||
self._dir = dir
|
self._dir = dir
|
||||||
if not os.path.exists(self._dir):
|
if not os.path.exists(self._dir):
|
||||||
@ -366,8 +362,7 @@ from django.core.db import db, DatabaseError
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
class _DBCache(_Cache):
|
class _DBCache(_Cache):
|
||||||
"""SQL cache backend"""
|
"SQL cache backend."
|
||||||
|
|
||||||
def __init__(self, table, params):
|
def __init__(self, table, params):
|
||||||
_Cache.__init__(self, params)
|
_Cache.__init__(self, params)
|
||||||
self._table = table
|
self._table = table
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import copy
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.utils.cache import get_cache_key, learn_cache_key, patch_response_headers
|
from django.utils.cache import get_cache_key, learn_cache_key, patch_response_headers
|
||||||
@ -49,7 +48,7 @@ class CacheMiddleware:
|
|||||||
return None # No cache information available, need to rebuild.
|
return None # No cache information available, need to rebuild.
|
||||||
|
|
||||||
request._cache_update_cache = False
|
request._cache_update_cache = False
|
||||||
return copy.copy(response)
|
return response
|
||||||
|
|
||||||
def process_response(self, request, response):
|
def process_response(self, request, response):
|
||||||
"Sets the cache, if needed."
|
"Sets the cache, if needed."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user