diff options
| author | Justin Bronn <jbronn@gmail.com> | 2007-08-26 01:10:53 +0000 |
|---|---|---|
| committer | Justin Bronn <jbronn@gmail.com> | 2007-08-26 01:10:53 +0000 |
| commit | 2052b508eb92c62fc0678efd4936c5ec1e0e735b (patch) | |
| tree | e510109b74b28c8ccef5f6955727cb9dce3da655 /django/core/cache | |
| parent | a7297a255f4bb86f608ea251e00253d18c31d9d4 (diff) | |
gis: Made necessary modifications for unicode, manage refactor, backend refactor and merged 5584-6000 via svnmerge from [repos:django/trunk trunk].
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@6018 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core/cache')
| -rw-r--r-- | django/core/cache/backends/filebased.py | 5 | ||||
| -rw-r--r-- | django/core/cache/backends/locmem.py | 17 | ||||
| -rw-r--r-- | django/core/cache/backends/memcached.py | 16 |
3 files changed, 28 insertions, 10 deletions
diff --git a/django/core/cache/backends/filebased.py b/django/core/cache/backends/filebased.py index faaf8910ce..d5415c8ace 100644 --- a/django/core/cache/backends/filebased.py +++ b/django/core/cache/backends/filebased.py @@ -1,7 +1,8 @@ "File-based cache backend" from django.core.cache.backends.simple import CacheClass as SimpleCacheClass -import os, time, urllib +from django.utils.http import urlquote_plus +import os, time try: import cPickle as pickle except ImportError: @@ -77,4 +78,4 @@ class CacheClass(SimpleCacheClass): raise EnvironmentError, "Cache directory '%s' does not exist and could not be created'" % self._dir def _key_to_file(self, key): - return os.path.join(self._dir, urllib.quote_plus(key)) + return os.path.join(self._dir, urlquote_plus(key)) diff --git a/django/core/cache/backends/locmem.py b/django/core/cache/backends/locmem.py index 0e21b80ed8..4c48c571b7 100644 --- a/django/core/cache/backends/locmem.py +++ b/django/core/cache/backends/locmem.py @@ -1,8 +1,13 @@ "Thread-safe in-memory cache backend." +import time +try: + import cPickle as pickle +except ImportError: + import pickle + from django.core.cache.backends.simple import CacheClass as SimpleCacheClass from django.utils.synch import RWLock -import copy, time class CacheClass(SimpleCacheClass): def __init__(self, host, params): @@ -20,7 +25,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 +43,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() diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py index 1ab019221a..52610daef1 100644 --- a/django/core/cache/backends/memcached.py +++ b/django/core/cache/backends/memcached.py @@ -1,6 +1,7 @@ "Memcached cache backend" from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError +from django.utils.encoding import smart_unicode, smart_str try: import cmemcache as memcache @@ -16,17 +17,22 @@ class CacheClass(BaseCache): self._cache = memcache.Client(server.split(';')) def get(self, key, default=None): - val = self._cache.get(key) + val = self._cache.get(smart_str(key)) if val is None: return default else: - return val + if isinstance(val, basestring): + return smart_unicode(val) + else: + return val def set(self, key, value, timeout=0): - self._cache.set(key, value, timeout or self.default_timeout) + if isinstance(value, unicode): + value = value.encode('utf-8') + self._cache.set(smart_str(key), value, timeout or self.default_timeout) def delete(self, key): - self._cache.delete(key) + self._cache.delete(smart_str(key)) def get_many(self, keys): - return self._cache.get_multi(keys) + return self._cache.get_multi(map(smart_str,keys)) |
