kuitos / axios-extensions

🍱 axios extensions lib, including throttle, cache, retry features etc...
MIT License
831 stars 49 forks source link

allow forceUpdate on `POST` requests #46

Closed peters313 closed 5 years ago

peters313 commented 5 years ago

would it be possible to allow a forceUpdate (or clear the cache for that matter) to happen on a Post/Put/Delete request? that way if you do simply just local state updates when adding/updating/deleting on the ui but if the component were to mount again, it would see that the cache is no longer there and make the API request to generate a new cache

kuitos commented 5 years ago

duplicated with https://github.com/kuitos/axios-extensions/issues/2

AndrewCraswell commented 5 years ago

@kuitos This is not a duplicate of #2. What I believe @peters313 is saying, is that certain methods against an endpoint should remove an existing GET from the cache.

For example, if I hit the endpoint like so: GET /api/profile/ [Real request] POST /api/profile/ [Should remove the Get from the cache since the object has likely changed] GET /api/profile/ [Real request] GET /api/profile/ [Pulls from cache]

This could get more advanced by checking the Status code response, but at the very least, PUT, POST, and DELETE methods are expected to modify the resource, so we should throw away any cached GET.

AndrewCraswell commented 5 years ago

For reference, seems that axios-cache-adapter operates like this by default as described here.

kuitos commented 5 years ago

sorry for my misunderstand, I think u could control your cache by yourself, as not every project follow the rest api spec, related issue https://github.com/kuitos/axios-extensions/issues/52