mistval / node-fetch-cache

Node-fetch with built-in response caching.
MIT License
51 stars 8 forks source link

Checking If Request Is Already in Cache #29

Closed dewaynehiggs closed 1 year ago

dewaynehiggs commented 1 year ago

Hi there! Awesome work regarding this package!

I do have a question, though. Is there a way I can check to see if a http request is already in cache? I have a scenario where I'm using a throttling mechanism to make sure I don't access certain API endpoints too quickly, but if I already have the results from those endpoints in cache, I would like to bypass that throttling altogether.

Thank you!

mistval commented 1 year ago

Hi, I have just pushed a new version 3.1.1 to NPM which I think will get you where to need to go, via support for the Cache-Control: only-if-cached header directive. Please check out the Cache-Control: only-if-cached Requests section in the README and let me know.

dewaynehiggs commented 1 year ago

Your newest release is exactly what I'm looking for! Thank you! This should work just fine.

liquidmetalrob commented 1 year ago

Thank you for explaining here that you need version 3.1.1 in order to use the cache-control functionality. I was getting very frustrated trying to get it to work and not realising I was on too old of a version to do it. So I recommend adding a note to the readme that explains that because it's not clear at the moment.

mistval commented 1 year ago

@liquidmetalrob You can look at the README for the version of the package that you're using via the "Versions" tab on npmjs.com. If you aren't in the habit of doing that you might have problems like that a lot, with other packages too.