Skip to content

Commit

Permalink
Added a use_cache flag to calls. Default is true.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rogelio authored and joshthecoder committed Oct 1, 2011
1 parent 33920f9 commit 290b24e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 0 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,5 @@ def testfilecache(self):
os.rmdir('cache_test_dir')

if __name__ == '__main__':

unittest.main()

3 changes: 2 additions & 1 deletion tweepy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ def verify_credentials(self):
""" 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 """
Expand Down
5 changes: 3 additions & 2 deletions tweepy/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class APIMethod(object):
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
Expand Down Expand Up @@ -108,7 +109,7 @@ def execute(self):

# 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:
Expand Down Expand Up @@ -172,7 +173,7 @@ def execute(self):
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
Expand Down

0 comments on commit 290b24e

Please sign in to comment.