From: Joshua Roesslein Date: Sun, 22 Dec 2013 01:42:09 +0000 (-0800) Subject: Add API.cached_result. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=066146062076f37677507df6312bc9374420019a;p=tweepy.git Add API.cached_result. This will be True if the last result was cached. Otherwise this will be False if the result was freshly requested from the Twitter API servers. --- diff --git a/tests/test_api.py b/tests/test_api.py index d83a844..c21a11e 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -326,6 +326,13 @@ class TweepyAPITests(TweepyTestCase): } self.assertTrue(expected_dict in languages) + def testcachedresult(self): + self.api.cache = MemoryCache() + self.api.home_timeline() + self.assertFalse(self.api.cached_result) + self.api.home_timeline() + self.assertTrue(self.api.cached_result) + class TweepyCacheTests(unittest.TestCase): timeout = 2.0 diff --git a/tweepy/binder.py b/tweepy/binder.py index 6c58847..29eacae 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -104,6 +104,8 @@ def bind_api(**config): self.path = self.path.replace(variable, value) def execute(self): + self.api.cached_result = False + # Build the request URL url = self.api_root + self.path if len(self.parameters): @@ -123,6 +125,7 @@ def bind_api(**config): else: if isinstance(cache_result, Model): cache_result._api = self.api + self.api.cached_result = True return cache_result # Continue attempting request until successful