lru-cache
A Javascript LRU-cache for node and/or browser, featuring:
- LRU cache logic
- Singleton caches per value type
- Event registry for cache change events
Installation
npm install --save @swarmy/lru-cache
Basic Usage
Caching
import {getCache} from "@swarmy/lru-cache";
...
const userCache = getCache("User");
userCache.set(user.id, user);
...
let user = userCache.get(userId);
if (!user) {
await fetchUser(userId);
}
- For the same value type (here "User"), getCache will always return the same cache instance.
- For detailed description of all cache methods, have a look at
Cache Events
WIP
Quality
Develop
git clone https:
cd lru-cache
npm install
npm run build
npm run test
npm run generate-doc
Detailed Usage
Caching
WIP
Cache Events
WIP