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

uniquecache

v0.0.2

Published

cache that you found some unique value and make sure you don't tell anyone else in this process that it is unique while you save it.

Downloads

3

Readme

Build Status

uniquecache

cognitive overhead.. if you need to implement this kind of logic you have at least on async call. i wanted it to look exactly the same.

fetch(myUniqueObject,Date.now(),function(err,unique){
  if(unique) console.log('yayayayaya!')
})

but its kinda weird that i have to pass time you know bro?

you may not know what time you are processing i certainly cannot assume that you are processing things related to now!

so to use it.. you know. you require the library

var uniquecache = require('uniquecache');

The function returns the fetch function curried with cache magic. This will only call your real fetch function when it really has to. You know.. the useful part.

var fetch = uniquecache(
  ['id'] // use these object key's values to build the unique key from each object passed to fetch
  ,function(obj,time,callback){
    callback(false,true);
    calls++;
  }
  ,1 // check every milisecond for data older than a milisecond [defaults to 5 minutes]
  ,1 // only ever hold one item. like ever. [defaults to 10000]
); 

Really curry!? thats kind an effed api bro. its spicy and stuff why can't this be a stream.

Well if you look at it in http://maxogden.github.io/flavors there are clearly things that go with curry and though node is not on the list i think we'll recover.

but im a library implementor i hate cognitive overhead what does it look like for me?

var fetch = uniquecache(['id'],function(obj,time,cb){
  api.call(url+'/'+obj.id,function(err,data){
    cb(err,data?false:true);
  });
});

module.exports = function(obj,cb){
  fetch(obj,Date.now(),cb);
}

oh thats not bad. thanks.

this will be useful to you only if

  • unique hits are clustered mostly in time. around the length of interval.
  • this works better when timestamps are mostly in order.
  • if i have a pending request for the key im not unique.
  • basic lru implemented for items. Items with a time difference of interval are culled each specified interval based on input timestamp.
  • this lru's worse part is the full key scan each interval. have millions of keys in cache? if not it probably wont break your app unless your interval is too tight.