ttl
ttl
npm i ttl
ttl

ttl

Simple in-memory cache for JavaScript

by Rui Hu

1.3.1 (see all)License:MITTypeScript:Not Found
npm i ttl
Readme

ttl Build Status

Simple in-memory cache for JavaScript

Installation

$ npm install ttl --save

Usage

var Cache = require('ttl');
var cache = new Cache({
    ttl: 10 * 1000,
    capacity: 3
});

cache.on('put', function(key, val, ttl) { });
cache.on('del', function(key, val) { });
cache.on('drop', function(key, val, ttl) { });
cache.on('hit', function(key, val) { });
cache.on('miss', function(key) { });

cache.put('foo', 'bar');
cache.put('ping', 'pong', 20 * 1000);
cache.put('yo', 'yo', 30 * 1000);
cache.put('whats', 'up'); // emit 'drop' event

cache.get('foo');     // > 'bar'
cache.get('yo');      // > 'yo'
cache.get('ping');    // > 'pong'
cache.get('lol');     // > undefined

// after 10 seconds
cache.get('foo');     // > undefined
cache.size();         // > 2
cache.del('ping')     // > 'pong'
cache.get('ping');    // > undefined
cache.size();         // > 1
cache.clear();
cache.size();         // > 0

License

MIT

Downloads/wk

28.4K

GitHub Stars

12

LAST COMMIT

3yrs ago

MAINTAINERS

1

CONTRIBUTORS

1

OPEN ISSUES

0

OPEN PRs

1
VersionTagPublished
1.3.1
latest
5yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate