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

dirty-cache

v0.1.10

Published

Simple wrapper around lru-cache that uses pub-sub for notifying of a dirty entry.

Downloads

37

Readme

dirty-cache

Basic wrapper around lru-cache that uses pub-sub for notifying of a dirty entry. Not all lru-cache functionality is exposed, mainly get, set, and del.

One difference to be aware of, values in cache are a deep clone of the inserted value so that any modifications made to the object before or after being cached don't change modify the object in cache.

var obj = {foo: 'bar'};
cache.set(1, obj);

obj == cache.get(1); // false
obj.foo == cache.get(1).foo; // true

Build Status

Usage

var dirtyCache = require('dirty-cache');

var cache1 = dirtyCache({name: 'users', max: 100, maxAge: 60000, redis: {host: 'localhost', port: 6379}});
var cache2 = dirtyCache({name: 'users', max: 100, maxAge: 60000, redis: {host: 'localhost', port: 6379}});

cache1.set('0087e434-9dfe-4ac9-99e9-fbdbd9f834f5', {name: 'TJ'});
cache1.get('0087e434-9dfe-4ac9-99e9-fbdbd9f834f5'); // {name: 'TJ'}

cache2.set('0087e434-9dfe-4ac9-99e9-fbdbd9f834f5', {name: 'TJ', age: 31}, true);

cache1.get('0087e434-9dfe-4ac9-99e9-fbdbd9f834f5'); // undefined
cache2.get('0087e434-9dfe-4ac9-99e9-fbdbd9f834f5'); // {name: 'TJ', age: 31}

Options

  • name The name of this cache. Needed when using same cache on distributed system. Optional or not needed when used as a standalone cache.
  • max The maximum number of objects in the cache, Not setting this is kind of silly, since that's the whole purpose of this lib, but it defaults to Infinity.
  • maxAge Maximum age in ms. Items are not pro-actively pruned out as they age, but if you try to get an item that is too old, it'll drop it and return undefined instead of giving it to you.
  • redis.host Redis host
  • redis.port Redis port
  • redis.password Redis password (if needed)

API

set(key, value, dirty)

Sets the value of key in the local cache. If dirty, notifies other caches their value is stale.

get(key)

Gets the latest value of key, or undefined if was not present in local cache or has been evicted due to dirtiness or expiration.

del(key)

Deletes a key out of the local cache and notifies distributed caches to evict key.

Events

"error"

Error event in the case of connection errors to redis.

"ready"

Client will emit ready after the conenction to redis has been successfully established.