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

1.0.7 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

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

Weekly Downloads

1

Version

1.0.7

License

none

Last publish

Collaborators

  • robertboulton
  • seraph2000
  • hamza.samih
  • notlee
  • emmalewis
  • aendra
  • the-ft
  • rowanmanning
  • chee
  • alexwilson