memoize_until v1.0.3
MemoizeUntil
A unique Memoization Pattern which memoizes until the next time metric - could be until the next minute, hour, day, week.
Get Started
Install memoize_until
with:
npm install memoize_until --save-dev
Usage
const MemoizeUntil = require('memoize_until').MemoizeUntil
MemoizeUntil.fetch('min', 'default', () => {
return 'SomeComplexOperation';
})
options:
min
: Metric until when you want to memoize. Can be one of 'min', 'hour', 'day', 'week'default
: All metric levels come with a 'default' key. More can be added by initializingMemoizeUntil
with extra keyscb
: callback function. This callback function must return a value which needs to be memoized/cached.
Initialisation
To add custom keys to each metric, pass a custom object to the init
function of MemoizeUntil
.
MemoizeUntil.init({
min: ['custom1', 'custom2']
})
MemoizeUntil.fetch('min', 'custom1', () => {
return 'SomeComplexOperation';
})
Extend
To add custom keys during runtime to any metric, use the extend
function of MemoizeUntil
.
let runtime_key = 'runtime_key';
MemoizeUntil.extend('min', runtime_key)
MemoizeUntil.fetch('min', runtime_key, () => {
return 'SomeComplexOperation';
})
Nulls
if the value to be memoized is undefined
or null
, MemoizeUntil
wraps it underneath a pseudo null-like object called NullObject
and always returns undefined
. This ensures that even nulls are memoized.
License
Ritikesh
Licensed under the MIT license.