refactor: deduplicate cache revalidation actions

This commit is contained in:
Shivam Mishra
2026-06-08 18:39:40 +05:30
parent 0deb026f9d
commit 625302ac3c
8 changed files with 129 additions and 71 deletions
@@ -0,0 +1,14 @@
export const createCacheRevalidateAction =
({ api, mutation, clearMutation, getData = response => response.data }) =>
async ({ commit }, { newKey }) => {
try {
const isExistingKeyValid = await api.validateCacheKey(newKey);
if (isExistingKeyValid) return;
const response = await api.refetchAndCommit(newKey);
if (clearMutation) commit(clearMutation);
commit(mutation, getData(response));
} catch (error) {
// Ignore error
}
};