From eaa91f6b9783f69e3b099b3b9bc36fc23d14be02 Mon Sep 17 00:00:00 2001 From: gilles Date: Sat, 11 Sep 2010 02:59:04 +0800 Subject: [PATCH] memcache cache --- tweepy/cache.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tweepy/cache.py b/tweepy/cache.py index 9a343e3..8d9cab8 100644 --- a/tweepy/cache.py +++ b/tweepy/cache.py @@ -262,3 +262,39 @@ class FileCache(Cache): continue self._delete_file(os.path.join(self.cache_dir, entry)) +class MemCacheCache(Cache): + """Cache interface""" + + def __init__(self, client, timeout=60): + """Initialize the cache + client: The memcache client + timeout: number of seconds to keep a cached entry + """ + self.client = client + self.timeout = timeout + + def store(self, key, value): + """Add new record to cache + key: entry key + value: data of entry + """ + self.client.set(key, value, time=self.timeout) + + def get(self, key, timeout=None): + """Get cached entry if exists and not expired + key: which entry to get + timeout: override timeout with this value [optional]. DOES NOT WORK HERE + """ + return self.client.get(key, key) + + def count(self): + """Get count of entries currently stored in cache. RETURN 0""" + return 0 + + def cleanup(self): + """Delete any expired entries in cache. NO-OP""" + pass + + def flush(self): + """Delete all cached entries. NO-OP""" + pass -- 2.25.1