delete get cache best practices? #742
-
When I initiate a POST operation, I want to clear the cache for a specific GET request, but I don't know the id associated with that GET request. Is there a way to know the id generated by axios-cache-interceptor? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You need to know the request ID, otherwise there's nothing you can do to delete the correct request. A good pattern I'm currently using is to manually define all requests IDS inside an enum and use them accordingly where I need. const IDS = {
createUser: 'create-user',
listUsers: 'list-users'
}
function listUsers() {
return axios.get('url...', { id: IDS.listUsers, <other options> });
}
function createUser(data) {
return axios.post('url', data, {
id: IDS.createUser,
update: {
[IDS.listUsers]: 'delete'
}
});
} |
Beta Was this translation helpful? Give feedback.
You could've tested it out... But yes, you have to provide different ID for each parameter, you can do something like: