marco.pms.web/src/slices/apiCacheSlice.jsx

24 lines
591 B
JavaScript

import { createSlice } from "@reduxjs/toolkit";
const apiCacheSlice = createSlice({
name: "apiCache",
initialState: {},
reducers: {
cacheApiResponse: (state, action) => {
const { key, data } = action.payload;
state[key] = data;
},
clearApiCacheKey: (state, action) => {
const { key } = action.payload;
delete state[key];
},
flushApiCache: () => {
return {}; // Resets the entire cache
},
},
});
export const { cacheApiResponse, clearApiCacheKey, flushApiCache } =
apiCacheSlice.actions;
export default apiCacheSlice.reducer;