@financial-times/n-map-cache-light

In-memory cache with no dependencies

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
@financial-times/n-map-cache-light
Minified + gzip package size for @financial-times/n-map-cache-light in KB

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

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.