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

sacjs

v1.3.0

Published

Set Associative Cache

Downloads

171

Readme

sacjs

Generic n-way Set Associative Cache for node.js.

Build Status npm version Coverage Status

Install

npm install sacjs

Usage

var Cache = require('sacjs');

var cache = new Cache({ assoc: 4, size: 10000, algorithm: 'lru' });

cache.put(key, data);

// ...

var data = cache.get(key);

// ...

cache.del(key);

// ...

cache.clear();

key used to store data in the cache can be any scalar or object/array. You can supply serialize option that will be used to convert keys to strings, otherwise json-stable-stringify will be used. Serialized keys are hashed using Dan Bernstein's algorithm.

Options

Options object is passed to cache constructor.

  • assoc - cache associativity level (the number of slots per set). For any given key an item can be stored in any of the slots in the set. Higher associativity improves hit ratio but reduces cache performance.

  • size - cache size (the number of sets of slots the cache will store). The total number of items the cache can store is assoc * size

  • algorithm - eviction algorithm. Can be:

    • 'lru' (least recently used)
    • 'mru' (most recently used)
    • 'lfu' (least frequently used)
    • 'mfu' (most frequently used)
    • object with three functions: created, accessed (passed the slot) and evict (passed the set - the hash of slots). Implementations of eviction algorithms are in algorithms.js and cache.spec.js.
  • serialize - custom key serialization algorithm. Should return the same string for the same key every time it is called. By default, json-stable-stringify is used. Pass false to skip serializing (if all keys are strings or numbers).

Cache statistics

Cache usage statistics are available in stat property of the cache instance. The stat object has the following properties:

  • misses - the number of misses
  • hits - the number of hits
  • stored - the number of items that were stored in free slots
  • replaced - the number of item that were replaced (different value for the same key)
  • evicted - the number of items that were evicted