Commit 290b24e8 authored by rogelio's avatar rogelio Committed by Joshua Roesslein
Browse files

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.
parent 33920f9f
......@@ -379,6 +379,5 @@ class TweepyCacheTests(unittest.TestCase):
os.rmdir('cache_test_dir')
if __name__ == '__main__':
unittest.main()
......@@ -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 """
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment