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

cabrel-catbox

v0.1.2

Published

Fork of https://github.com/spumko/catbox -- Multi-strategy object caching service

Readme

This is a fork, for the original, see: Catbox

Multi-strategy object caching service

Build Status

catbox is a multi-strategy key-value object store. It includes support for Redis, MongoDB, and a limited memory store (not suitable for production environments). catbox provides two interfaces: a low-level Client and a high-level Policy.

Installation

In order to reduce module dependencies, catbox does not depend on the mongodb or redis modules. To use these strategies, each service must be available on the network and each module must be manually installed.

Client

The Client object provides a low-level cache abstraction. The object is constructed using new Client(options) where:

  • options - is an object with the following keys:
    • engine - the cache server implementation. Options are:
      • redis
      • mongodb
      • memory
      • an object with catbox compatible interface (use the memory cache implementation as prototype).
    • partition - the partition name used to isolate the cached results across multiple clients. The partition name is used as the MongoDB database name or as a key prefix in Redis. To share the cache across multiple clients, use the same partition name.
    • additional strategy specific options:
      • MongoDB:
        • host - the MongoDB server hostname. Defaults to 127.0.0.1.
        • port - the MongoDB server port. Defaults to 27017.
        • username - when the mongo server requires authentication. Defaults to no authentication.
        • password - the authentication password when username is configured.
        • poolSize - number of connections. Defaults to 5.
      • Redis:
        • host - the Redis server hostname. Defaults to 127.0.0.1.
        • port - the Redis server port. Defaults to 6379.
        • password - the Redis authentication password when required.
        • database - the Redis database number to connect to. Defaults to null (uses the Redis default of 0).
      • Memory:
        • maxByteSize - sets an upper limit on the number of bytes that can be stored in the cached. Once this limit is reached no additional items will be added to the cache until some expire. The utilized memory calculation is a rough approximation and must not be relied on. Defaults to 104857600 (100MB).

API

The Client object provides the following methods:

  • start(callback) - creates a connection to the cache server. Must be called before any other method is available. The callback signature is function(err).
  • stop() - terminates the connection to the cache server.
  • get(key, callback) - retrieve an item from the cache engine if found where:
    • key - a cache key object (see below).
    • callback - a function with the signature function(err, cached). If the item is not found, both err and cached are null. If found, the cached object contains the following:
      • item - the value stored in the cache using set().
      • stored - the timestamp when the item was stored in the cache (in milliseconds).
      • ttl - the remaining time-to-live (not the original value used when storing the object).
  • set(key, value, ttl, callback) - store an item in the cache for a specified length of time, where:
    • key - a cache key object (see below).
    • value - the string or object value to be stored.
    • ttl - a time-to-live value in milliseconds after which the item is automatically removed from the cache (or is marked invalid).
    • callback - a function with the signature function(err).
  • drop(key, callback) - remove an item from cache where:
    • key - a cache key object (see below).
    • callback - a function with the signature function(err).

Any method with a key argument takes an object with the following required properties:

  • segment - a caching segment name. Enables using a single cache server for storing different sets of items with overlapping ids.
  • id - a unique item identifies (per segment).

Policy

The Policy object provides a convenient cache interface by setting a global policy which is automatically applied to every storage action. The object is constructed using new Policy(options, [cache, segment]) where:

  • options - is an object with the following keys:
    • expiresIn - relative expiration expressed in the number of milliseconds since the item was saved in the cache. Cannot be used together with expiresAt.
    • expiresAt - time of day expressed in 24h notation using the 'MM:HH' format, at which point all cache records for the route expire. Cannot be used together with expiresIn.
    • staleIn - number of milliseconds to mark an item stored in cache as stale and reload it. Must be less than expiresIn.
    • staleTimeout - number of milliseconds to wait before checking if an item is stale.
  • cache - a Client instance (which has already been started).
  • segment - required when cache is provided. The segment name used to isolate cached items within the cache partition.

API

The Policy object provides the following methods:

  • get(id, callback) - retrieve an item from the cache where:
    • id - the unique item identifier (within the policy segment).
    • callback - a function with the signature function(err, cached) where cached is the object returned by the client.get() with the additional isStale boolean key.
  • set(id, value, ttl, callback) - store an item in the cache where:
    • id - the unique item identifier (within the policy segment).
    • value - the string or object value to be stored.
    • ttl - a time-to-live override value in milliseconds after which the item is automatically removed from the cache (or is marked invalid). This should be set to 0 in order to use the caching rules configured when creating the Policy object.
    • callback - a function with the signature function(err).
  • drop(id, callback) - remove the item from cache where:
    • id - the unique item identifier (within the policy segment).
    • callback - a function with the signature function(err).
  • ttl(created) - given a created timestamp in milliseconds, returns the time-to-live left based on the configured rules.
  • getOrGenerate(id, generateFunc, callback) - get an item from the cache if found, otherwise calls the generateFunc to produce a new value and stores it in the cache. This method applies the staleness rules. Its arguments are:
    • id - the unique item identifier (within the policy segment).
    • generateFunc - a function with the signature function(callback = function (err, result)) where result is the value to be stored.
    • callback - a function with the signature function(err, value, cached, report) where:
      • err - any errors encountered.
      • value - the fetched or generated value.
      • cached - the cached object returned by policy.get() is the item was found in the cache.
      • report - an object with logging information about the operation.