js-lru
js-lru copied to clipboard
No constructor for taking the json output format as input
The toJSON() function returns contents of the cache as an array of objects, with key and value fields. However there is no way to input contents in the same format.
You can do
LRUMap.prototype.fromJSON = function(cache) {
return new LRUMap(cache.map(it => {
return [it.key, it.value]
}))
}
Happy to accept a PR for a function like that.
- Make it a "static" (non-prototype) function on LRUMap
- Add a test for it
@rsms created PR #41 to address this issue.