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 🙏

© 2024 – Pkg Stats / Ryan Hefner

proactive-cache

v1.0.2

Published

simple in memory key/value cache with proactive autoclean

Downloads

3

Readme

Simple NodeJs in-memory caching

A simple in memory key/value cache with proactive cleaning. Actually, the cache is based on a single object (So the cache size limit depends on max size of a single object). Each item of the cache has its own timer to avoid setInterval on an empty cache.

NPM

Usage:

var Cache = require("proactive-cache");
var options = {
    expirationDelay: 5000, //ms
    dispose: function (key, value) { console.log('key:', key, 'value:', value); }
};
var myCache = new Cache(options);
myCache.set('key', 'value');
myCache.get("key");

Options

  • useClones (default: true): Enable or disable cloning on variables. If true, all items will be deeply cloned before storing in the cache. Otherwise, only the reference will be saved.
  • expirationDelay (default: 60000): Delay in ms before removing the item from the cache.
  • renewExpiration (default: true): Enable or disable the renewal of the delay when getting or storing an item
  • dispose(key, value): Function called when an item expired. This function will be synchronous

API

  • set(key, value, [delay]) (optional: delay)

    Add or update an item in the cache. Delay allows you to overwrite the global expirationDelay on a specific item. If it's an update, the expiration delay of this item will be renew.

  • get(key)

    Returns the key value (or null if not found) renewing the expiration delay.

  • mget(keys)

    Returns an object with keys as properties {'key1': 'value1', 'key2': 'value2'} (or an empty object {} if no keys found). For each key, the expiration delay will be renew.

  • peek(key)

    Returns the key value (or null if not found) without renewal on expiration delay.

  • del(key)

    Deletes a key out of the cache.

  • mdel(keys)

    Deletes keys out of the cache.

  • reset()

    Clears the cache entirely, throwing away all values and clearing all timers items without calling dispose function.

  • has(key)

    Checks if a key is in the cache, without renewing expiration delay.

  • keys()

    Returns an array of the keys in the cache.

  • values()

    Returns an array of the values in the cache.

  • itemCount()

    Returns total quantity of objects currently in cache.

Test

Run:

  npm test

There are about 35 tests using Sinon.js and ChaiJS

Licence

The MIT License (MIT)

Copyright (c) 2015 Djothi Grondin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.