Socket
Book a DemoInstallSign in
Socket

lru-halfexpired

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lru-halfexpired

lru cache but get supports a fill callback

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

halfexpired-lru

lru-cache where get accepts an optional "fill" callback. A fill callback would be used to populate a value in the background before it is really expired. set also supports ttl per key.

example


var cache = require('halfexpired-lru');

cache.set('a',1);

cache.get('a',function(err,key,value,ttl,remaining){
  if(err == 'halfexpired') {
    request(url,function(err,data){
      if(err) {
	// if i set it halfexpired will hit next in half the remaining time.
	cache.set(key,value,remaining);
	console.log('that flakey api failed again! good thing my value is not completely expired ;)');
      } else cache.set(key,value,ttl);
    })
  }
});

Keywords

lru

FAQs

Package last updated on 20 Dec 2012

Did you know?

Socket

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