fast-cache

1.1.1 • Public • Published

fast-cache

Caches a method that returns a promise and does so really fast.

Installation

Download node at nodejs.org and install it, if you haven't already.

npm install fast-cache --save

Usage

/* eslint-disable */
 
import fastCache from 'fast-cache';
import { keyCache } from 'fast-cache';
 
// this will only be called once since it'll get cached
const fn = () => {
  // fetch is just an example, could be something so simple as Promise.resolve(...)
  return fetch('http://example.com')
    .then(response => response.json());
};
const cached = fastCache(fn);
 
cached().then((json) => {
  console.log('json1', json);
});
 
cached().then((json) => {
  console.log('json2', json);
});
 
const keyBased = keyCache((id) => {
  // again, this is just an example. just needs to be something returning a promise
  return fetch(`http://example.com/${id}`);
});
 
keyBased('id1').then((response) => {
  console.log('id1 response', response);
});
 
keyBased('id2').then((response) => {
  console.log('different response from id1', response);
});
 

Tests

npm install
npm test

Dependencies

None

Dev Dependencies

License

MIT

Generated by package-json-to-readme

Keywords

none

Install

npm i fast-cache

DownloadsWeekly Downloads

1,504

Version

1.1.1

License

MIT

Last publish

Collaborators

  • kesla