You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since some API calls can be cached, it would be nice if ratelimit could somehow be made aware of the cache.
For example, with the very simple to use requests_cache library you can cache all responses made by the requests library by default.
If your request is r = requests.get('http://example.com/api') you can check r.from_cache which will return True if the response was read from cache.
It would be awesome if I could easily make ratelimit aware of the last time an actual API call was made using r.from_cache in my function so it would only rate limit actual API calls. Something like this:
Would this be terribly difficult to implement or is there already a way to do this that isn't documented in the readme? The hook method doesn't account for time the rest of the script is running between API requests so it wastes a lot of time.
The text was updated successfully, but these errors were encountered:
Can't you have a cache decorator wrap around what you have? So the cache decorator would be hit first and it would return the results if there's something in the cache. If not, the rate limit decorator would be hit that would check if there have been to many API calls.
I haven't tried it, but I'm using Django's cache_memoize and I think it could work like this:
Since some API calls can be cached, it would be nice if ratelimit could somehow be made aware of the cache.
For example, with the very simple to use requests_cache library you can cache all responses made by the requests library by default.
If your request is
r = requests.get('http://example.com/api')
you can checkr.from_cache
which will return True if the response was read from cache.It would be awesome if I could easily make ratelimit aware of the last time an actual API call was made using
r.from_cache
in my function so it would only rate limit actual API calls. Something like this:Would this be terribly difficult to implement or is there already a way to do this that isn't documented in the readme? The hook method doesn't account for time the rest of the script is running between API requests so it wastes a lot of time.
The text was updated successfully, but these errors were encountered: