Socket
Socket
Sign inDemoInstall

ttl

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ttl

Simple in-memory cache for JavaScript


Version published
Weekly downloads
26K
decreased by-25.18%
Maintainers
1
Install size
4.48 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 20 Nov 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc