fast-cache
v1.1.1
Published
Caches a method that returns a promise and does so really fast.
Downloads
5,280
Readme
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
- async-cache-promise: async-cache - but with promises
- babel-cli: Babel command line.
- babel-core: Babel compiler core.
- babel-plugin-syntax-async-functions: Allow parsing of async functions
- babel-plugin-transform-async-to-generator: Turn async functions into ES2015 generators
- babel-polyfill: Provides polyfills necessary for a full ES2015+ environment
- babel-preset-es2015: Babel preset for all es2015 plugins.
- babel-tape-runner: Babel + Tape for running your ES Next tests
- miclint: mic lint cli
- package-json-to-readme: Generate a README.md from package.json contents
- tapava: the syntax of ava, run through tape
License
MIT
Generated by package-json-to-readme