node package manager


Share information about cache states

Shared Cache

Allow applications share cache-state and data over Redis.


function update_info(cache_key, next) {
    db.findOne({}, next)
Cache = require('shared-cache')
info = Cache.create('caching key', true, update_info)
possibly_stale = info.get();
info.get(function(err, definitely_not_stale) {


Returns a caching instance from the singleton pool.

This function both returns and executes a callback.

  • In the event the data is not stale, both will receive the same value.
  • If the data is stale, the return will be the stale value whilst the callback is held until the data is available.

Update the value of this cache, optionally broadcasting the new value to other instances. This marks the data as not stale.

Add the callback onto a queue to be fired when the update_callback returns, and call the update_callback if it hasn't already been called.

Mark this data as stale. If auto_update is true then it update_callback is fired. If broadcast is true, other instances are notified to update their caches.