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

expire-cache

v1.0.0

Published

A simple cache that supports expiring and namespace.

Downloads

2,156

Readme

expire-cache v0.2.0 Build Status

A simple cache that supports expiring and namespace.

DEMO

expireCache('key1', 123);
console.log(expireCache('key1')); // 123

expireCache.set('key2', 456);
console.log(expireCache.get('key2')); // 456

var cache1 = expireCache.namespace('test');
cache1('key', 789);
console.log(cache1('key')); // 789

var cache2 = cache1.namespace('test');
cache2('key', 123);
console.log(cache1('key')); // 789
console.log(cache2('key')); // 123

Installation

Node.js:

npm install expire-cache

Bower:

bower install expire-cache

browser:

<script src="/pathTo/expire-cache/index.js"></script>

API

var expireCache = require('expire-cache');

expireCache()

expireCache(key)

expireCache(object)

expireCache(object, expire)

expireCache(key, value)

expireCache(key, value, expire)

expireCache.get()

expireCache.get(key)

expireCache.set(object)

expireCache.set(object, expire)

expireCache.set(key, value)

expireCache.set(key, value, expire)

expireCache.remove()

expireCache.remove(key)

expireCache.remove(keys)

expireCache.namespace(namespace)

expireCache.namespace(namespace, expire)

expireCache()

expireCache.get()

return all data

  var data1 = expireCache();
  var data2 = expireCache.get();

expireCache(key)

expireCache.get(key)

return data for key

  var data1 = expireCache('test1');
  var data2 = expireCache.get('test2');

expireCache(object)

expireCache(key, value)

expireCache.set(object)

expireCache.set(key, value)

set data with default expire time(5 sec), return expireCache

  expireCache({test1: 123});
  expireCache.set({test2: 123});
  expireCache({test3: 1234, test4: 12345});
  expireCache('key1', 123);
  expireCache.set('key2', 123);
  expireCache('key3', 1234)('key4', 12345);

expireCache(object, expire)

expireCache(key, value, expire)

expireCache.set(object, expire)

expireCache.set(key, value, expire)

set data with expire time, return expireCache

  expireCache({test1: 123}, 1); // expire in 1 sec
  expireCache.set({test2: 123}, 1); // expire in 1 sec
  expireCache('key1', 123, 10); // expire in 10 sec
  expireCache.set('key2', 123, 10); // expire in 10 sec

expireCache.remove()

remove all data, return expireCache

  expireCache.remove();

expireCache.remove(key)

expireCache.remove(key1, key2, ...)

expireCache.remove([key1, key2, ..])

remove data for key, return expireCache

  expireCache.remove('key').remove('key1', 'key2', 'key3');
  expireCache.remove(['key1', 'key2', 'key3']);
  expireCache.remove('key', ['key1', 'key2'], ['key3', 'key4', 'key5']);

expireCache.namespace(namespace)

expireCache.namespace(namespace, expire)

return a sub expireCache with namespace and expire time(default 5 sec)

  var cache1 = expireCache.namespace('cache1');
  var cache2 = expireCache.namespace('cache2', 10);
  var cache3 = cache2.namespace('cache3', 1);

  cache3({key1: 1, key2: 2});
  cache3('key3', 3);
  cache3(); // return {key1: 1, key2: 2, key3: 3}

  cache2.remove();
  cache3(); // return {}