Function composition wrapperd that will allow you to cache returned values
npm install with-cache
bash
npm install --save with-cache
`
Usage
Simplest case:
`javascript
import { withCache } from 'with-cache';
function heavyOperation(arg1, arg2) {
//...do something
}
const heavyOperatuionWithCaching = withCache(heavyOperation);
//this call will run heavyOperation function
const result1 = heavyOperatuionWithCaching("pass", "secret");
//this call return previously cached value
const result2 = heavyOperatuionWithCaching("pass", "secret");
`
withCache can also accept options as a second argument. See docs
`javascript
import { withCache } from 'with-cache';
function heavyOperation(arg1, arg2) {
//...do something
}
const customKeymaker = (arg1, arg2) => arg1 + arg2;
class CustomCache extends Map {}
const heavyOperatuionWithCaching = withCache(heavyOperation, {
keymaker: customKeymaker,
ttl: 420,
cache: new CustomCache()
});
``