Open bpolaszek opened 5 years ago
Hi @bpolaszek
Thanks a lot for your interest and feedback!
TL;DR I completely agree with all your suggestions 😄
- Caching strategies
Very interesting to use the cache headers by default and then let the developer override it with a fixed TTL.
- Include query params by default
Yes I guess it would make more sense but only if the cache invalidation is not automatic like it is now. The current default behavior was what was needed in the first app I developed that used this library, not relevant anymore.
- Canonicalize URL
Absolutely needed yes 😄
- (Completely) Ignore non-GET requests by default *
- Optionally allow other methods
Makes sense as well if we remove the automatic cache invalidation on POST
requests
- TTL unit should be seconds, not milliseconds
Why is this so? Is it the way servers express it? My knowledge on cache falls short here.
All these are breaking changes to the current behavior so should be released in a major version.
Just being curious, how do you use axios-cache-adapter
? on the client, server or even both?
If you'd like to contribute to making this shift I'd be delighted to help.
Cheers
Hi @RasCarlito,
Thank you for your feedback!
I use it on the client side (my stack is PHP for the back-end, VueJS for the front).
Commonly cache expirations are expressed in seconds (see here) - and I honestly don't see a use case where the cache should invalidate at a specific millisecond.
All these are big breaking changes indeed and should be heavily documented 🙂
Unfortunately I'm not a very good JS coder, but I contributed on a similar package for a PHP library, so don't hesitate to ping me if I can help in architecting this.
Just looked at how the Cache API works, it can be a good start for abstracting a Native strategy + a Browser storage (because it won't work in Node):
Cache-Control
headerVary
headerRelated: #53
Should be nice indeed! Where did you find documentation about Cache API parsing Cache-Control
and Vary
headers? I can't seem to find it 😞
TBH I didn't find the explicit information, and this deserves to be tested. I guessed this because the cache API has a ignoreVary
option, which means it reads the Vary
header by default, which only makes sense if it reads Cache-Control
first, IMO. And it has no TTL option so I really doubt it doesn't rely on response headers, otherwise there's no way to invalidate the cache.
@bpolaszek
Currently a POST request matching the same URL than a GET request results in a cache item removal. IMHO non-allowed methods (default to non-GET) should be completely discarded from both read and writes for 3 reasons: ...
- Even if
POST /foos
succeeds, it is the developer's responsibility to decide whether or notPOST /foo
should invalidateGET /foos
(then they could also decide thatPUT /foo
both invalidatesGET /foo
andGET /foos
, for instance). The library should not enforce that and be completely blind from non-allowed-methods calls
Has been fixed in the latest build. Allowing you to override the invalidate function.
Hey there,
Thanks for the good work! I needed cache management with Axios and this library does a good job.
I'm not a Javascript expert but if I may suggest some enhancements:
Cache-Control
andVary
headers) - would be the default behavior (major version bump) - because that's what we expect at first when using a cache adapter* Currently a POST request matching the same URL than a GET request results in a cache item removal. IMHO non-allowed methods (default to non-GET) should be completely discarded from both read and writes for 3 reasons:
GET /foos
,POST /foos
andGET /foos
results in 3 cache MISS, even ifPOST /foos
failed.POST /foos
succeeds, it is the developer's responsibility to decide whether or notPOST /foo
should invalidateGET /foos
(then they could also decide thatPUT /foo
both invalidatesGET /foo
andGET /foos
, for instance). The library should not enforce that and be completely blind from non-allowed-methods calls.What do you think?