diff options
| author | Gary Wilson Jr <gary.wilson@gmail.com> | 2007-07-15 06:24:54 +0000 |
|---|---|---|
| committer | Gary Wilson Jr <gary.wilson@gmail.com> | 2007-07-15 06:24:54 +0000 |
| commit | ae7f04caab1b4f2a2b509b036499e4e042caaac6 (patch) | |
| tree | b32456f6ef266c330ebc4c78fba8474d4b07dd7d /django | |
| parent | 208352e5d753ebc11c407a22dd0629f8f9b61592 (diff) | |
Fixed #3012 -- Changed the locmem cache backend to use pickle instead of deepcopy to make it compatible with iterators (which cannot be copied). Patch from Sundance.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5703 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/cache/backends/locmem.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/django/core/cache/backends/locmem.py b/django/core/cache/backends/locmem.py index 0e21b80ed8..468d1e629b 100644 --- a/django/core/cache/backends/locmem.py +++ b/django/core/cache/backends/locmem.py @@ -2,7 +2,11 @@ from django.core.cache.backends.simple import CacheClass as SimpleCacheClass from django.utils.synch import RWLock -import copy, time +import time +try: + import cPickle as pickle +except ImportError: + import pickle class CacheClass(SimpleCacheClass): def __init__(self, host, params): @@ -20,7 +24,10 @@ class CacheClass(SimpleCacheClass): elif exp < now: should_delete = True else: - return copy.deepcopy(self._cache[key]) + try: + return pickle.loads(self._cache[key]) + except pickle.PickleError: + return default finally: self._lock.reader_leaves() if should_delete: @@ -35,7 +42,10 @@ class CacheClass(SimpleCacheClass): def set(self, key, value, timeout=None): self._lock.writer_enters() try: - SimpleCacheClass.set(self, key, value, timeout) + try: + super(CacheClass, self).set(key, pickle.dumps(value), timeout) + except pickle.PickleError: + pass finally: self._lock.writer_leaves() |
