lru-cache-object
A simple proxy to lru-cache that creates plain javascript objects that behave like an lru cache.
Accepts the same configuration options as lru-cache
example
basic
const lru = ;const o = ;ocat = 'meow';console; // ==> 'meow' const o2 = ; // init with 2 item maxo2cat = 'meow';o2dog = 'woof';o2pig = 'oink';console; // ==> ['pig', 'dog']
recipes
with a redux reducer
With some caveats its possible to use it as lru cache reducer
const myReducer = state = items: action if actiontype === 'SOME_ACTION' return ...state items: Object return state;;
caveats:
- can not use spread operator
- this essentially modifies the original object which is a bit of a best practice no-no
- if you data is so large that you need this, it maybe be an indicator of a bigger architectural issue