1
0
mirror of https://github.com/django/django.git synced 2025-10-29 08:36:09 +00:00

Fixed #4845 -- Fixed some problems with Unicode usage and caching. Thanks,

Jeremy Dunck.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5718 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick
2007-07-16 09:36:10 +00:00
parent 7aac81d280
commit 2679bc0304
3 changed files with 36 additions and 19 deletions

View File

@@ -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))

View File

@@ -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))