From: Josh Roesslein Date: Thu, 30 Jul 2009 19:03:09 +0000 (-0500) Subject: Make MemoryCache picklable. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0f3f11931f69146123bb3f0878da6925aeb4b9a7;p=tweepy.git Make MemoryCache picklable. --- diff --git a/tweepy/cache.py b/tweepy/cache.py index 1e1b37e..9062f22 100644 --- a/tweepy/cache.py +++ b/tweepy/cache.py @@ -44,6 +44,16 @@ class MemoryCache(Cache): self._entries = {} self.lock = threading.Lock() + def __getstate__(self): + # pickle + return {'entries': self._entries, 'timeout': self.timeout} + + def __setstate__(self, state): + # unpickle + self.lock = threading.Lock() + self._entries = state['entries'] + self.timeout = state['timeout'] + def _is_expired(self, entry, timeout): return timeout > 0 and (time.time() - entry[0]) >= timeout