Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2bc6e136b0
Fetching contributors…

Cannot retrieve contributors at this time

59 lines (41 sloc) 1.513 kb
Alternative Django cache backend.
import simplejson as json
except ImportError:
import json
from django.core.cache import get_cache
from django.core.cache.backends.memcached import MemcachedCache
from django.contrib.sessions.backends import cache as session_cache
class SessionStore(session_cache.SessionStore):
def __init__(self, session_key=None):
self._cache = get_cache('json')
super(SessionStore, self).__init__(session_key)
class MemcachedCacheJSON(MemcachedCache):
"""Memcache store with JSON serialization
We want node.js applications to be able to read the stuff Django
stores to memcached so instead of pickling the data we'll
serialize it to json.
This is kind of a hack because looking at python-memcached's
source it seems *really* intent on using pickle.
def _cache(self):
if getattr(self, '_client', None) is None:
self._client = self._lib.Client(self._servers,
return self._client
class Pickler(object):
def __init__(self, fp, *args, **argv):
self.fp = fp
def dump(self, obj):
json.dump(obj, self.fp)
class Unpickler(object):
def __init__(self, fp, *args, **argv):
self.fp = fp
def load(self):
return json.load(self.fp)
Jump to Line
Something went wrong with that request. Please try again.