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

sifaka

v0.8.16

Published

Sifaka is a pluggable caching library with an emphasis on protecting the backend from being overloaded.

Downloads

13

Readme

Sifaka

Build Status

Sifaka is a pluggable caching library with an emphasis on protecting the backend from being overloaded. Approaches taken:

  • Cache Stampede / dog piling protection by maintaining a distributed lock between cache clients, so the work function is executed at most once at any time for a given key.
  • Allowing stale data to be served for a configurable period of time. During this time, one request will be triggered to update the cache for the key.
  • Configurable cache policies, allowing stale and expiry times to be calculated based upon the duration of the operation (e.g. if an operation takes 30s to complete, you may wish to recalculate it less frequently than an operation that takes 30ms to complete).

Backends

There are currently two backends available - an in-memory cache for testing purposes, and a Redis backend. You will need the redis module installed to use the redis backend.

Cache Policies

There are currently two cache policies available:

  • Static - you can pass values in seconds for expiryTime and staleTime in the options, and these fixed values will be used for all keys.
  • Duration - you can set minimum and maximum values for staleTime and expiryTime and values will be chosen based on the duration of the work function.

Methods

sifaka.get(key,workFunction,[options], callback)

Try to retrieve an item from the cache. If it is not there, either wait for another cache client to do the work (if it is already underway) or do the work locally. The value will then be returned via callback(err, data, meta, extra). The workFunction should callback(err, data, extra), where extra is an optional object to store alongside the data.

Options Values
options.metaOnly - request that metadata only be returned from the backend in either a hit or miss scenario

| options.metaOnly value | cache (hit|miss) | data returned | work function called | |:---:|:---:|:---:|:---:| | not set / null | hit | y | n | | not set / null | miss | y | if required | | "hit" | hit | n | n | | "hit" | miss | y | if required | | "miss" | hit | y | n | | "miss" | miss | n | n |

This means you can short circuit the work function on a miss and fetching data from the backend on a hit. This may be useful to:

Return data on a hit, but not recalculate the data on a miss Recalculate on a miss, but only report the existence on a hit.

sifaka.exists(key,[options], callback)

Check the state of an item in the cache. Will be returned by callback(err, meta)

Testing

  • mocha tests can be run using npm test mocha or make test!
  • there is a loadtest harness in /loadtest. Run node index.js --handler [handler] in one console, then hit localhost on port 8002 (e.g. with the node package loadtest: node loadtest.js -n 5000 -c 20 http://127.0.0.1:8002 --rps 50). There are some example results with various handlers: no caching (work function gets called for every request), using the node-cache module - which will hit the work with a stampede, and two sifaka handlers.

Why Sifaka?

There are only two hard problems in Computer Science: cache invalidation and naming things.

  • Phil Karlton

Why not. I decided to spend more cycles on getting the caching side of things right, rather than coming up with a better name. Also, they're awesome.