@parthar/ttl-cache

1.0.0 • Public • Published

TTL Cache

TTL cache with an accuracy of 1-minute for evicting items

Installation

$ npm install @parthar/ttl-cache --save

Usage

// create
var TTLCache = require("@parthar/ttl-cache");
var cache = new TTLCache({
    ttl: 15, // Integer - key-ttl in minutes; default: 15-min
    extend: false // boolean - extend TTL on get; default: false
});

// events
cache.on("evict", function(key, val) { }); // key evicted

// methods
cache.set("ping", "pong");
cache.set("ying", "yang");
cache.get("ping"); // pong
cache.get("ying"); // yang
cache.get("foo"); // undefined
cache.size(); // 2
cache.keys(); // ["ping", "ying"]
cache.values(); // ["pong", "yang"]
cache.ttl("ying"); // milli-secs since epoch at which key will expire
cache.del("ping"); // evict event ping/pong
cache.get("ping"); // undefined
cache.size(); // 1

// after 15-min; evict event for ying/yang
cache.get("ping"); // undefined
cache.get("ying"); // undefined
cache.get("foo"); // undefined
cache.size(); // 0

// clean-up
cache.clear(); // del all keys
cache.unref(); // stop ttl checks

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    0

Package Sidebar

Install

npm i @parthar/ttl-cache

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

5.07 kB

Total Files

4

Last publish

Collaborators

  • partharamanujam