How to use the lru-cache.default function in lru-cache

To help you get started, we’ve selected a few lru-cache examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github recruit-tech / redux-pluto / src / shared / packages / redux-effects-fetchr-cache / index.js View on Github external
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);
    }

lru-cache

A cache object that deletes the least-recently-used items.

ISC
Latest version published 2 months ago

Package Health Score

87 / 100
Full package analysis

Popular lru-cache functions