@financial-times/n-map-cache-light
v1.0.7
Published
In-memory cache with no dependencies
Downloads
5
Readme
n-map-cache-light
Basic, configurable in-memory cache. No dependencies.
Installation
npm install --save @financial-times/n-map-cache-light
Quick start
const MapCache = require('@financial-times/n-map-cache-light').MapCache;
const options = {
ttl: 3600, // seconds
interval: 7200, // seconds - purge interval
memory: 100 * 1024 * 1024, // bytes
capacity: 100 // items held in cache
};
// all properties are optional
// if none specified, default to 100MB, 1h TimeCache
let cache = new MapCache(options);
MapCache
extends ECMAScript Map
.
// use like Map
cache.set(key, value);
cache.get(key);
cache.delete(key);
cache.clear();
for(let [key, value] of cache.entries()) {
...
}
ByteSize utility
A simple library to estimate the size of JavaScript objects in bytes.
const ByteSize = require('@financial-times/n-map-cache-light').ByteSize;
Usage
let computedSize = new ByteSize(myBigNestedObject);
const size = computedSize.value; // bytes
const megabytes = computedSize._format('MB'); // megabytes