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:
|
||||
|
||||
def __init__(self, params):
|
||||
timeout = params.get('timeout', 300)
|
||||
try:
|
||||
|
@ -132,8 +131,7 @@ except ImportError:
|
|||
_MemcachedCache = None
|
||||
else:
|
||||
class _MemcachedCache(_Cache):
|
||||
"""Memcached cache backend."""
|
||||
|
||||
"Memcached cache backend."
|
||||
def __init__(self, server, params):
|
||||
_Cache.__init__(self, params)
|
||||
self._cache = memcache.Client([server])
|
||||
|
@ -161,8 +159,7 @@ else:
|
|||
import time
|
||||
|
||||
class _SimpleCache(_Cache):
|
||||
"""Simple single-process in-memory cache"""
|
||||
|
||||
"Simple single-process in-memory cache."
|
||||
def __init__(self, host, params):
|
||||
_Cache.__init__(self, params)
|
||||
self._cache = {}
|
||||
|
@ -230,11 +227,11 @@ try:
|
|||
import cPickle as pickle
|
||||
except ImportError:
|
||||
import pickle
|
||||
import copy
|
||||
from django.utils.synch import RWLock
|
||||
|
||||
class _LocMemCache(_SimpleCache):
|
||||
"""Thread-safe in-memory cache"""
|
||||
|
||||
"Thread-safe in-memory cache."
|
||||
def __init__(self, host, params):
|
||||
_SimpleCache.__init__(self, host, params)
|
||||
self._lock = RWLock()
|
||||
|
@ -250,7 +247,7 @@ class _LocMemCache(_SimpleCache):
|
|||
elif exp < now:
|
||||
should_delete = True
|
||||
else:
|
||||
return self._cache[key]
|
||||
return copy.deepcopy(self._cache[key])
|
||||
finally:
|
||||
self._lock.reader_leaves()
|
||||
if should_delete:
|
||||
|
@ -284,8 +281,7 @@ import os
|
|||
import urllib
|
||||
|
||||
class _FileCache(_SimpleCache):
|
||||
"""File-based cache"""
|
||||
|
||||
"File-based cache."
|
||||
def __init__(self, dir, params):
|
||||
self._dir = dir
|
||||
if not os.path.exists(self._dir):
|
||||
|
@ -366,8 +362,7 @@ from django.core.db import db, DatabaseError
|
|||
from datetime import datetime
|
||||
|
||||
class _DBCache(_Cache):
|
||||
"""SQL cache backend"""
|
||||
|
||||
"SQL cache backend."
|
||||
def __init__(self, table, params):
|
||||
_Cache.__init__(self, params)
|
||||
self._table = table
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import copy
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
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.
|
||||
|
||||
request._cache_update_cache = False
|
||||
return copy.copy(response)
|
||||
return response
|
||||
|
||||
def process_response(self, request, response):
|
||||
"Sets the cache, if needed."
|
||||
|
|
Loading…
Reference in New Issue