def do_test_cache(self, do_fetch, num_fetches, num_requests, num_db_fetches): # On the first fetch, all requests should have been fetched from # the data store. self.assert_stats(num_fetches, num_requests, num_db_fetches) # On the second fetch of the same data, the listener shouldn't # have any stats incremented as the data should have been fetched # from local cache. do_fetch() self.assert_stats(num_fetches, num_requests, num_db_fetches) # If we clear the local cache and request the same keys, # the data should be fetched from memcache. DataFetcher.reset() DataFetcher.set_listener(DataFetcherTestListener()) do_fetch() self.assert_stats(num_fetches, num_requests, 0)
def setUp(self): DataFetcher.reset() DataFetcher.set_listener(DataFetcherTestListener())