rsms / js-lru

A fast, simple & universal Least Recently Used (LRU) map for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No constructor for taking the json output format as input

Tuupertunut opened this issue · comments

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.

  1. Make it a "static" (non-prototype) function on LRUMap
  2. Add a test for it

@rsms created PR #41 to address this issue.