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

zip-cache

v1.0.0

Published

Cache your async lookups and store them compressed in memory.

Downloads

2

Readme

zip-cache

Build Status NPM

Cache your async lookups and store them (gzip) compressed in memory. This module is just a light wrapper around isaacs/async-cache, even this Readme ;-)

Installation

npm install zip-cache

Example

Let's say you have to look up JSON from a database. But you are ok with only looking up the info once every 10 minutes (since it doesn't change that often), and you want to limit your cache size to 1000 objects. The objects will be held as gzipped buffers in memory. This might be silly for some cases, but could save precious memory on cheap VPSs.

Note: Currently zip-cache only handles JSON.stringifyable objects.

You can do this:

var cache = new AsyncCache({
  // options passed directly to the internal lru cache
  max: 1000,
  maxAge: 1000 * 60 * 10,
  // method to load a thing if it's not in the cache.
  // key must be unique in the context of this cache.
  load: function (key, cb) {
    // this method will only be called if it's not already in cache, and will
    // cache the result in the lru.
    getTheJsonFromYourDB(key, cb)
  }
})

// then later..
cache.get('key', function (er, item) {
  // maybe loaded from cache, maybe just fetched
})

Except for the load method, all the options are passed unmolested to the internal lru-cache.

Methods

  • get(key, cb) If the key is in the cache, then calls cb(null, cached) on nextTick. Otherwise, calls the load function that was supplied in the options object. If it doesn't return an error, then cache the result. Multiple get calls with the same key will only ever have a single load call at the same time.

  • set(key, val, [cb]) Seed the cache. This doesn't have to be done, but can be convenient if you know that something will be fetched soon. Due to the async nature of zlib compression, this method also takes an optional callback function.

  • reset() Drop all the items in the cache.

  • del(key) Deletes a key out of the cache.

  • has(key) Check if a key is in the cache, without updating the recent-ness or deleting it for being stale.

  • peek(key) Returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.

    (If you find yourself using this a lot, you might be using the wrong sort of data structure, but there are some use cases where it's handy.)

Tests

npm test

License

MIT