1.0.1 • Published 5 years ago

lru-cache-persist v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

lru-cache-persist

LRU cache 持久化

Installation

  • Run the following command.
npm install --save lru-cache-persist
  • Import the library.
import Cache from "lru-cache-persist";

Usage

You initialize a cache using the following.

const cache = new Cache({
  namespace: "myapp",
  policy: {
    maxEntries: 50000,
    persist: false,
  },
});

Multiple caches can be mantained in an application by instantiating caches with different namespaces.

Setting a key's value in the cache

cache.set("hello", "world");
// key 'hello' is now set to 'world' in namespace 'myapp'

Get an item in the cache

const value = cache.get("key1");
console.log(value);
// 'hello'
});

For more usage examples, see the tests.