1.0.1 • Published 8 years ago

tiny-ttl-cache v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

NPM version Build Status Dependency Status

Simple TTL cache. put and get.

Suitable for use in browsers and Node.js.

Install

$ npm install --save tiny-ttl-cache

Usage

var TTLCache = require('tiny-ttl-cache');

var maxSize = 100;
var timeToLive = 10 * 1000; // 10s in ms

var cache = new TTLCache(maxSize, timeToLive);
cache.put('key', 'value');
cache.get('key'); // returns 'value'

// 10 seconds later
cache.get('key'); // returns null

cache.flush(); // Empties the cache

TTL Eviction Policy

Once the cache reaches its maximum size, the item with the shortest TTL is removed.

Development

npm install
npm test

License

MIT © Andy Hume