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

varcache

v0.0.2

Published

A pure memory based cache for Javascript.

Readme

varcache

A pure memory based cache for Node.js

Installation

npm install varcache

Usage

var cache = require('varcache');

// Storing an item in the cache.
cache.set('test', 'Something quite awesome!');

// Getting an item from the cache.
var test = cache.get('test');

// Deleting an item from the cache.
cache.delete('test');

// Storing an item in the cache with expiration and callbacks.
cache.set(
	'test',
	'Semething even more awesome...',
	5000,
	function (key, data) {
		console.log('Just stored "' + key + '" with:');
		console.log(data);
	},
	function (key) {
		console.log('"' + key + '" just expired.');
	}
);

This should print this:

Something quite awesome!
Just stored "test" with:
Semething even more awesome...

... 5 seconds later ...

"test" just expired.

Available functions

Functions

clear

Clears the entire cache hold of entries.

Available parameters:

  • callback (function)

Simple call:

cache.clear();

Can be extended to trigger a callback after the items are cleared.

cache.clear(function () {
	console.log('Cache is not cleared.');
});

debug

Enables, or disables, debug mode, which logs evething it does to the console.

Available parameters:

  • value (boolean)

Simple call:

cache.debug();

Can be extended to specify the boolean value to turn it on or off.

cache.debug(false);

delete

Deletes an entry by-key or several items if an array of keys are passed.

Available parameters:

  • key/keys (string/array)
  • callback (function)

Simple call:

cache.delete('test-key-1');

Or with an array of keys:

cache.delete([ 'test-key-2', 'test-key-3' ]);

Can be extended to trigger a callback for each key which is deleted.

cache.delete('test-key-1', function (key) {
	console.log('Just deleted key: "' + key + '".');
});

get

Gets the stored value for the given key in the cache.

Available parameters:

  • key (string)
  • callbackHit (function)
  • callbackMiss (function)

Simple call:

var value = cache.get('key');

Can be extended to trigger callbacks for both hit and miss.

var value = cache.get(
	'key',
	function (key, data) {
		console.log('Found key: "' + key + '" with value:');
		console.log(data);
	},
	function (key) {
		console.log('No data cached for key: "' + key + '".');
	}
);

hitCount

Returns the number of key-hits recorded, which is how many times data has been requested from the cache. This requires that the recordHist() function has been called.

Available parameters:

  • callback (function)

Simple call:

var count = cache.hitCount();

Can be extended to trigger a callback with the number.

cache.hitCount(function (count) {
	console.log('Total hits for keys are: ' + count.toString());
});

hitLog

Returns the log of hits, which returns the entire log for every hit against the cache. This requires that the recordHist() function has been called.

Available parameters:

  • callback (function)

Simple call:

var hits = cache.hitLog();

Can be extended to trigger a callback with the log.

cache.hitLog(function (hits) {
	console.log(hits);
});

keys

Returns all stored keys, which is convenient for management

Available parameters:

  • callback (function)

Simple call:

var keys = cache.keys();

Can be extended to trigger a callback with the keys.

cache.keys(function (keys) {
	console.log(keys);
});

keysCount

Returns the number of keys stored.

Available parameters:

  • callback (function)

Simple call:

var count = cache.keysCount();

Can be extended to trigger a callback with the number.

cache.keysCount(function (count) {
	console.log(count);
});

missCount

Returns the number of key-misses recorded, which is how many times data has been requested without existing in the cache. This requires that the recordMisses() function has been called.

Available parameters:

  • callback (function)

Simple call:

var count = cache.missCount();

Can be extended to trigger a callback with the number.

cache.missCount(function (count) {
	console.log('Total misses for keys are: ' + count.toString());
});

missLog

Returns the log of misses, which returns the entire log for every miss against the cache. This requires that the recordMisses() function has been called.

Available parameters:

  • callback (function)

Simple call:

var misses = cache.missLog();

Can be extended to trigger a callback with the log.

cache.missLog(function (misses) {
	console.log(misses);
});

recordHits

Enables, or disables, recording of hits in the cache. Default for this is set to false.

Available parameters:

  • value (boolean)

Simple call:

cache.recordHits();

Can be extended to specify the boolean value to turn it on or off.

cache.recordHits(false);

recordMisses

Enables, or disables, recording of misses in the cache. Default for this is set to false.

Available parameters:

  • value (boolean)

Simple call:

cache.recordMisses();

Can be extended to specify the boolean value to turn it on or off.

cache.recordMisses(false);

set

Creates, or updates, an item in the cache with all the fixins.

Available parameters:

  • key (string)
  • data (any)
  • ttl (int)
  • callbackSet (function)
  • callbackExpires (function)

Simple call:

cache.set('key', 'value');

This stores the "value" by the "key" forever. Can be extended to include how many milliseconds the value is to be stored in the cache.

cache.set('key', 'value', 5000);

This will store the data for 5 seconds. If you set 0, the data is stored without an expiration. Can also be extended to trigger callbacks when the data is set and when the data expires.

cache.set(
	'key',
	'value',
	5000,
	function (record) {
		console.log('This is the newly created record, which contains some metadata:');
		console.log(record);
	},
	function (key) {
		console.log('The entry with key: "' + key + '" just expired.');
	}
);