npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

expirable

v0.1.0

Published

Expirable cache

Downloads

70

Readme

Expirable

Automatic expiring "cache" for Node.js. There must be tons of modules like these, but I couldn't find anyone that suites my needs. Just something simple but useful enought to transformed in to a module. Oh and the syntax is pretty as well <3

API

var Expirable = require('expirable');

// all the keys you stuff in to the cache are saved for 5 minutes.
var cache = new Expirable('5 minutes');

// add a new item to the cache, expires in 5 minutes, as that is what we
// configured above.
cache.set('key', value);

// add item to the cache, but for 10 minutes.
cache.set('key', value, '10 minutes');

// get item from the cache, this will automatically update the internal last
// used value, so it will be expired after 5 minutes, without any interaction
value = cache.get('key');

// same as above, except it will not touch the internal last used value and it
// will expire 5 minutes after you have set it
value = cache.get('key', true);

// check if a value exists
cache.has('key') ? 'yes' : 'no';

// remove a key from the cache.
cache.remove('key');

// when a key is removed from the cache it will emit an event for it. This is
// useful when you want to re-cache an item again when it expires.
cache.on('key:removed', function (expired) {
  // The expired boolean tells you if the key was removed because it was expired
  // or if it was a manual removal
});

// update the expiree of a key
cache.expire('key', '10 seconds');
cache.expire('kex'); // alias for cache.remove, as it expired directly

// stop the interal setinterval that scan for out of date keys
cache.stop();

// start it again.
cache.start();

// kill everything, nuke that motherfucker.
cache.destroy();

// Oh! so you want to store the output of a Stream? sure!
var stream = cache.stream('key', fs.createReadStream(..), '10 seconds');

// stream is the result of fs.createReadStream
// once the stream fires it's `done` event, we will store the data.

// iterate over the cache
cache.forEach(function (key, value) {
  console.log(key, value);
});

License

MIT