-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Invalidation callback #304
Comments
If I changed the implementation to a one following this typescript definition, would everything be ok? export type CacheProperties<R = unknown, D = unknown> = {
...
update: Record<string, CacheUpdater<R, D>> | ((storage: AxiosStorage, response: CacheAxiosResponse<R, D>) => MaybePromise<void>);
} Then you'll have to interact with the storage by yourself and invalidate/update any request that you want. |
@arthurfiorette I believe that should work! As long as I have access to the current query id, and can set it on global config, it should be fine. |
At some point you'll have to do this, either using a custom key generator to wrap all "similar" requests or doing an if/else inside cache.update to invalidate all "similir" requests. |
What do you mean by that? |
I mean that I need to be able to set it when calling
I would probably change the key generator (using |
@nolde, are you up to create a PR? |
@nolde, i got time and created a PR with the above changes. Can you take a look at it before I merge into prod? |
* feat: implemented general cache updater function * test: added tests * docs: included cache update warning
@nolde, just released v0.10.7, can you test it out? |
I just started using axios-cache-interceptor today and so far so good! Request ID generation (url parameters included) How can I invalidate/update cached GET requests in the interceptor? IDs are generated and not fixed like "list-posts" from your example. |
Moved to #344 |
Similar to
axios-cache-adapter
callback calledinvalidate
.With this callback, we could easily fine-tune the interceptor's behaviour, by inspecting the current request id, method and what not.
As an example, this is what I have right now, along with
axios-cache-adapter
:It allows me to pass in extra arguments (like
forceRefresh
in this case) straight from each request, allows me to test for id patterns for clearing cache, etc.The reason is that the current
update[id]
method can be a little too simplistic. I may have an user requestingGET /things?filter=alpha
andGET /things?filter=beta
, and I want both cached. When the user doesPOST /thing
, I want to invalidate both entries with different filters. Currently, I would have to implement that into each request point, making sure I generate suitable IDs and clearing all caches after a success.The callback would allow me to better defined default invalidation behaviour into a centralised place.
Edit:
Another common case is multiple page loading.
GET /things
andGET /things?nextPageToken=ABCDE
are both parts of the same query, and both need to be invalidated if a new item is added.The text was updated successfully, but these errors were encountered: