Skip to content

Commit

Permalink
Merge pull request sebleier#19 from jaylett/picklable-cache-object
Browse files Browse the repository at this point in the history
Make cache object picklable.
  • Loading branch information
sebleier committed Jul 22, 2011
2 parents 6504a3d + 7361e20 commit ff58e47
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions redis_cache/cache.py
Expand Up @@ -37,7 +37,11 @@ def __init__(self, server, params):
"""
Connect to Redis, and set up cache backend.
"""
self._init(server, params)

def _init(self, server, params):
super(CacheClass, self).__init__(params)
self._initargs = { 'server': server, 'params': params }
options = params.get('OPTIONS', {})
password = params.get('password', options.get('PASSWORD', None))
db = params.get('db', options.get('DB', 1))
Expand All @@ -56,6 +60,12 @@ def __init__(self, server, params):
port = 6379
self._client = redis.Redis(host=host, port=port, db=db, password=password)

def __getstate__(self):
return self._initargs

def __setstate__(self, state):
self._init(**state)

def make_key(self, key, version=None):
"""
Returns the utf-8 encoded bytestring of the given key as a CacheKey
Expand Down

0 comments on commit ff58e47

Please sign in to comment.