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

39 lines
851 B
JavaScript

import { store } from "../store/store";
import {
cacheApiResponse,
clearApiCacheKey,
flushApiCache,
} from "../slices/apiCacheSlice";
import {setLoginUserPermmisions} from "./globalVariablesSlice";
// Cache data
export const cacheData = (key, data) => {
store.dispatch(cacheApiResponse({ key, data }));
};
// Get cached data
export const getCachedData = (key) => {
return store.getState().apiCache[key];
};
// Clear specific cache key
export const clearCacheKey = (key) => {
store.dispatch(clearApiCacheKey({ key }));
};
// Clear all cache
export const clearAllCache = () => {
store.dispatch(flushApiCache());
};
export const cacheProfileData = ( data) => {
store.dispatch(setLoginUserPermmisions(data));
};
// Get cached data
export const getCachedProfileData = () => {
return store.getState().globalVariables.loginUser;
};