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

slim-cache

v1.1.1

Published

Super Fast Lightweight Cache with a Map like interface

Downloads

22

Readme

slim-cache

CircleCI NPM Downloads node License MIT

Super Fast Lightweight Cache with a Map like interface

Highlights

  • Super Fast

  • Written in Typescript

  • Easy Map Like Interface

Usage

Super Fast Lightweight Cache with a Map like interface


  import SlimCache from 'slim-cache';

  cache = new SlimCache(); // creates new cache
  cache.set('hello', 'world');
  cache.get('hello'); // 'world'
  cache.has('hello'); // true
  cache.clear('hello'); //true
  cache.isEmpty(); // true
  cache.set('hello', 'world');
  cache.clean(); // Clears every key of the cache rendering it empty
  cache.isEmpty(); // true
  cache.flush({'new': 'cache'}); // replaces internal cache object with user provided object
  cache.get('new'); // cache

Benchmark

All benchmarks were run using benchmark

Memoization

fast-memoize was used with various caches to memoize a standard recursive fibonacci function

Benchmark was run for all the memoized functions to find 40th fibonacci number


┌──────────────┬─────────────┬──────────────────────────┬─────────────┐
│ NAME         │ OPS/SEC     │ RELATIVE MARGIN OF ERROR │ SAMPLE SIZE │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ slim-cache   │ 402,727,692 │ ± 0.35%                  │ 93          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ object cache │ 391,995,589 │ ± 0.61%                  │ 94          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ map-cache    │ 388,972,451 │ ± 1.58%                  │ 92          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ fast-memoize │ 334,922,846 │ ± 0.35%                  │ 91          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ native map   │ 265,225,627 │ ± 0.56%                  │ 90          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ vanilla      │ 1           │ ± 6.91%                  │ 7           │
└──────────────┴─────────────┴──────────────────────────┴─────────────┘

Legend

  • slim-cache : fibonacci function memoized using fast-memoize with SlimCache instance

  • object cache: fibonacci function memoized using fast-memoize with Empty Object based cache

  • map-cache: fibonacci function memoized using fast-memoize with MapCache instance

  • fast-memoize: default fast-memoize cache

  • native map: fibonacci function memoized using fast-memoize with Native ES6 Map based cache

  • vanilla: fibonacci function without memoization

Methods

has

┌────────────┬─────────────┬──────────────────────────┬─────────────┐
│ NAME       │ OPS/SEC     │ RELATIVE MARGIN OF ERROR │ SAMPLE SIZE │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ slim-cache │ 902,468,492 │ ± 1.63%                  │ 93          │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ native map │ 694,384,457 │ ± 0.62%                  │ 95          │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ map-cache  │ 686,595,656 │ ± 0.74%                  │ 90          │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ object     │ 184,851,669 │ ± 3.27%                  │ 86          │
└────────────┴─────────────┴──────────────────────────┴─────────────┘

get


┌────────────┬─────────────┬──────────────────────────┬─────────────┐
│ NAME       │ OPS/SEC     │ RELATIVE MARGIN OF ERROR │ SAMPLE SIZE │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ slim-cache │ 917,775,700 │ ± 0.42%                  │ 94          │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ map-cache  │ 914,493,164 │ ± 0.46%                  │ 92          │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ object     │ 913,072,253 │ ± 0.54%                  │ 91          │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ native map │ 667,015,102 │ ± 1.69%                  │ 91          │
└────────────┴─────────────┴──────────────────────────┴─────────────┘

set

┌──────────────┬─────────────┬──────────────────────────┬─────────────┐
│ NAME         │ OPS/SEC     │ RELATIVE MARGIN OF ERROR │ SAMPLE SIZE │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ object cache │ 916,023,083 │ ± 0.39%                  │ 96          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ slim-cache   │ 912,787,773 │ ± 0.50%                  │ 94          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ map-cache    │ 911,402,606 │ ± 0.56%                  │ 96          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ native map   │ 144,171,162 │ ± 0.48%                  │ 91          │
└──────────────┴─────────────┴──────────────────────────┴─────────────┘

License

MIT © Nivrith Mandayam Gomatam