1.0.7 • Published 8 years ago

@financial-times/n-map-cache-light v1.0.7

Weekly downloads
18
License
-
Repository
github
Last release
8 years ago

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
1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago