From: gilles Date: Fri, 10 Sep 2010 18:59:04 +0000 (+0800) Subject: memcache cache X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=eaa91f6b9783f69e3b099b3b9bc36fc23d14be02;p=tweepy.git memcache cache --- 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