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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cache-js

v0.0.7

Published

Cache container for nodejs and regular Javascript application.

Readme

cachejs

Cache container for nodejs and regular Javascript application.

NPM Version NPM Downloads Build Status

Why

CacheJS is a Cache container, it is designed to be a common cache interface, storage independent.

Installation and usage

In node application context:

npm install cachejs
var cachejs = require('cachejs');
var container = cachejs.Container();

var obj = { ... };
container.set('objid', obj, { lifetime: 5000 }); // store in cache for 5 sec.
...
var cachedObj = container.get('objid'); // retrieve from cache

In regular Javascript application context:

bower install cachejs
<script src="bower_components/cachejs/cache.js"></script>
<script src="bower_components/cachejs/storage/memory.js"></script>
<script src="bower_components/cachejs/cacheitem.js"></script>
<script src="bower_components/cachejs/container.js"></script>
<script>
var cache = new cachejs.Container();

// Same example than in NodeJS context.
</script>

All cachejs objects are located in CacheJS namespace of window.

API

Container

Container is a generic cache container model, its default store engine is MemoryCacheContainer. See Store Engine section for more information.

Container(options)

Container constructor accepts options object as unique parameter to configure it. Options may be overriden once created using options instance function.

.options(optKey [, optValue])

Get or set an option for this container.

Container options

Option | Default | Description -------------------|----------------------|-------------- lifetime | false | The default lifetime for stored objects in ms. Set false evaluated or negative expression for infinite lifetime. onUpdate | - | Callback function(objKey, oldVal, newVal) used each time an object is created or updated in container. onExpiry | - | Callback function(cacheItem)used each time an object expires in container. May be used to create an auto-refresh process for cacheItem.key value. storage | 'memory' | Storage engine {String|Function}. Native engines are 'memory'... (sorry that's all for now) pruningInterval | 60000 | Interval (in ms.) container checks for expired cache items

.set(objKey, obj [, options])

Stores obj in cache associated with objKey reference for further retrieving.

options parameter allow to specify some cache feature related to this stored item. This object is the same used to specify container options and overrides already defined container options. See Container options.

Returns the stored cache item.

CacheItem

Property | Description -------------------|-------------- storedAt | Storage date (Javascript Date object)

Function | Description -------------------|-------------- isExpired | Indicates whether cache value has expired or not value | Get or set cache item value.

Option | Description -------------------|-------------- lifetime | Lifetime of this cache item onExpiry | Callback used when cache item lifetime expires. Default value is container's one. onUpdate | Callback used when cache item value is updated. Default value is container's one.

Example:

var cacheItem = container.set('basket', { // Object stored
    customerEmail: '[email protected]',
    items: [
      { articleId: 45, quantity: 2 },
      { articleId: 12, quantity: 1 }
    ]
  }, {
    lifetime: 24 * 3600 * 1000, // 24h
    onExpiry: function(cacheItem) {
      // cacheItem.lifetime === 24 * 3600 * 1000
      // cacheItem.onExpiry === this
      
      // mailSender is a fake for this example
      var basket = cacheItem.getValue()
      mailSender.send(basket.customerEmail,
        'Hi, your basket created at ' + cacheItem.storedAt + ' has just expired.');
    }
  });

// Set option
cacheItem.options('lifetime', 5000);

// Get option
var updateCallback = cacheItem.options('onUpdate');

Nota bene: Some readonly fields are added to CacheItem instance once created: storedAt and cannot be overridden.

.get(objKey)

Retrieves a non-expired value from cache. objKey is the cache key of stored value. To retrieve item independently of its expired state, use getItem instead.

When no value retrieved for given objKey, returns null.

.has(objKey)

Returns true whether key objKey reference a valid (not expired) value in cache, otherwise false .

.getItem(objKey)

Retrieves an object cache item from cache or null.

var item = cache.getItem('basket');
/* item object:
{
  key: 'basket',
  storedAt: 1419153019947, // Ticks (e.g.: new Date().getTime())
  lifetime: 86400000, // 24h
  onUpdate: undefined,
  onExpiry: function(){ ... },
  isExpired: function() { ... }, // Returns true or false
  value: { ... } // cached object
}
*/

.prune()

Remove all expired items from cache container and aises onExpiry of all removed items.