From 290b24e814cb1058537a162697d079cdc876212d Mon Sep 17 00:00:00 2001 From: rogelio Date: Wed, 15 Jun 2011 14:23:11 -0500 Subject: [PATCH] Added a use_cache flag to calls. Default is true. This is to avoid caching calls like rate_limit_status which shouldn't ever be cached. Binder was modified to only cache when the flag is true. --- tests.py | 1 - tweepy/api.py | 3 ++- tweepy/binder.py | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests.py b/tests.py index c8bf554..4929cd3 100644 --- a/tests.py +++ b/tests.py @@ -379,6 +379,5 @@ class TweepyCacheTests(unittest.TestCase): os.rmdir('cache_test_dir') if __name__ == '__main__': - unittest.main() diff --git a/tweepy/api.py b/tweepy/api.py index 3ca294f..dafb739 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -323,7 +323,8 @@ class API(object): """ account/rate_limit_status """ rate_limit_status = bind_api( path = '/account/rate_limit_status.json', - payload_type = 'json' + payload_type = 'json', + use_cache = False ) """ account/update_delivery_device """ diff --git a/tweepy/binder.py b/tweepy/binder.py index bf2dec3..12933a0 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -25,6 +25,7 @@ def bind_api(**config): method = config.get('method', 'GET') require_auth = config.get('require_auth', False) search_api = config.get('search_api', False) + use_cache = config.get('use_cache', True) def __init__(self, api, args, kargs): # If authentication is required and no credentials @@ -108,7 +109,7 @@ def bind_api(**config): # Query the cache if one is available # and this request uses a GET method. - if self.api.cache and self.method == 'GET': + if self.use_cache and self.api.cache and self.method == 'GET': cache_result = self.api.cache.get(url) # if cache result found and not expired, return it if cache_result: @@ -172,7 +173,7 @@ def bind_api(**config): conn.close() # Store result into cache if one is available. - if self.api.cache and self.method == 'GET' and result: + if self.use_cache and self.api.cache and self.method == 'GET' and result: self.api.cache.store(url, result) return result -- 2.25.1