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 🙏

© 2025 – Pkg Stats / Ryan Hefner

keepsake

v0.1.0

Published

Keepsake of items infinitely or forget them after a number of times

Readme

KEEPSAKE

Keepsake of items infinitely or forget them after a number of times.

Example

See also the examples folder.

Installation

npm install keepsake

Usage

Include the module

var keepsake = require('keepsake');

Possible storages

  • MemoryStore for using memory storage

NB! For now you can only use the MemoryStore.

Setting up MemoryStore

Possible store options are the following :

  • ttl - define a global TTL in milliseconds for each items added, after that time the key will be removed (default to 0 means infinity)
  • overwrite - set if you want to update value for a key that already exists (default to false)
  • maxCacheSize - set the store size in bytes (default to 10485760 Bytes = 10 MB)

Example :

var MemoryStore = require('keepsake').MemoryStore;

// with custom options
var customCache = new MemoryStore({
	ttl: 1000,
	overwrite: true,
	maxCacheSize: 1024
});

// with defaults values
var defaultCache = new MemoryStore();

After initialization, you can update TTL, overwrite and maxCacheSize attributes with these methods :

  • setTTL - define new global time-to-live (in ms)
  • setOverwrite - set if store can update or not the key value
  • setMaxCacheSize - define new cache size (in bytes)

Example :

defaultCache.setTTL(5000); // set TTL to 5 seconds
defaultCache.setOverwrite(true); // key can be update
defaultCache.setMaxCacheSize(2048); // set max cache size to 2MB

Available methods

Add item(s) in store

Possible parameters :

  • Array - an array of object with 2 attributes : key and value
  • Function - callback function

Example :

// add one item
defaultCache.addItems(
	[
		{ "key": "one", "value": "oneValue" }
	],
	function (err) {
		if (err) return console.log(err);
		console.log('Item(s) added');
	}
);

// add more than one item
defaultCache.addItems(
	[
		{ "key": "one", "value": "oneValue" },
		{ "key": "two", "value": "twoValue" },
		{ "key": "three", "value": "threeValue" },
		{ "key": "four", "value": "fourValue" }
	],
	function (err) {
		if (err) return console.log(err);
		console.log('Item(s) added');
	}
);

NB! If the size of an element is greater than the available space, the least recently used items will be removed until there is enough space for the new element to add.

Retrieve item(s) from store

Possible parameters :

  • Array, String - can be a key or an array of keys
  • Function - callback function

Example :

// retrieve value from one item
defaultCache.retrieveItems(
	"one",
	function (err, data) {
		if (err) return console.log(err);
		if (!data) return console.log('Item(s) not found');
		console.log(data);
	}
);

// retrieve values from multiple items
defaultCache.retrieveItems(
	[ "one", "two", "three", "four" ],
	function (err, data) {
		if (err) return console.log(err);
		if (!data) return console.log('Item(s) not found');
		console.log(data);
	}
);

Remove item(s) from store

Possible parameters :

  • Array, String - can be a key or an array of keys
  • Function - callback function

Example :

// retrieve value from one item
defaultCache.removeItems(
	"one",
	function (err) {
		if (err) return console.log(err);
		console.log('Item(s) removed');
	}
);

// retrieve values from multiple items
defaultCache.removeItems(
	[ "one", "two", "three", "four" ],
	function (err, data) {
		if (err) return console.log(err);
		console.log('Item(s) removed');
	}
);

Clear store

Possible parameter :

  • Function - callback function

Example :

defaultCache.clear(function (err) {
	if (err) return console.log(err);
	console.log('Storage cleared');
});

Retrieve the number of items in store

Example :

console.log(defaultCache.getItemsCount()); // display the number of items in memory store

Tests

Run the tests with npm in keepsake directory

npm test

License

keepsake is licensed under MIT License.