Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function fetchrCacheMiddleware(config) {
const { excludes, ...cacheConfig } = { excludes: [], ...config };
const cache = createCache(cacheConfig);
return ({ dispatch }) => (next) => (action) => {
if (action.type !== FETCHR) {
return next(action);
}
const { type, resource, params } = action.payload;
if (type !== 'read' || excludes.includes(resource)) {
return next(action);
}
const key = `${resource}@@${JSON.stringify(params)}`;
const cachedResult = cache.get(key);
if (cachedResult) {
return Promise.resolve(cachedResult);
}