python-twitter icon indicating copy to clipboard operation
python-twitter copied to clipboard

Is the file cache not being used?

Open frnsys opened this issue 8 years ago • 5 comments
trafficstars

I'm trying to set a cache for the API with a long timeout:


api = twitter.Api(
    consumer_key=CONSUMER_KEY,
    consumer_secret=CONSUMER_SECRET,
    access_token_key=ACCESS_TOKEN,
    access_token_secret=ACCESS_TOKEN_SECRET,
    sleep_on_rate_limit=True
)

cache = twitter._FileCache(root_directory='/home/me/')
api.SetCache(cache)
api.SetCacheTimeout(60*60) # in seconds

but it doesn't actually seem to cache anything? Looking at api.py, I can't see anywhere that self._cache is being used.

frnsys avatar Oct 08 '17 01:10 frnsys

No, it doesn't appear to be used. I think that'd be a good call for the next point release. Let me know if you want to work on this, otherwise I can take a look soon.

jeremylow avatar Oct 20 '17 03:10 jeremylow

Just looked into this today, and there is still no reference to self._cache being used. Where is this intended to be used? On every request?

rraihansaputra avatar Jul 11 '19 13:07 rraihansaputra

I've done some digging into this. self._cache.Set() was last referenced on tag 1.0. I did not find any references on tags 1.1, 1.1.6, 2.0, 3.0, and branch master.

Last reference: https://github.com/bear/python-twitter/blob/v1.0/twitter.py#L4537

The test modules does test the _FileCache implementation, but does not test whether the Api actually uses the cache or not. No test for setting or getting the cache from the Api.

I'm not sure whether patching that into the current codebase is ideal as I'm not too familiar with the _FileCache situation, but it looks good to me. I haven't tested it yet though.

Last issue referencing cache is working: https://github.com/bear/python-twitter/issues/69 (before 1.0/1.1 release)

Affected Issues: https://github.com/bear/python-twitter/issues/589

Is there anything to be concerned with if I were to make a PR based on the 1.0 implementation?

rraihansaputra avatar Jul 11 '19 14:07 rraihansaputra

@bear can you take a look at this? I know this is an old issue, but opening up a new issue means duplicating this one.

rraihansaputra avatar Dec 04 '19 10:12 rraihansaputra

@jeremylow apologies for the ping, but can you look into this when you have the time? It's been years, and in my experience this creates a lot of unneccessary API timeouts as the cache is not used. Thank you in advance!

rraihansaputra avatar Dec 15 '21 07:12 rraihansaputra