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

node-tagged-cache

v0.0.4

Published

In-memory, performance-targeted caching module with ttl and tagging support.

Downloads

7

Readme

Fast NodeJS in-memory caching with tagging

Probably the fastest NodeJS caching system yet.
It is much like memcached or redis but provides you with ability to set tags for cache entries and drop them all together when you need it.
Note that this module does not clone stored arrays/objects and operates only with their refs.

Performance

As the entries store node-tagged-cache uses Map due to it's total overperforming regular objects. All below performance tests made on Win10, Intel I7 5820K, 16GB DDR4 RAM.
All numbers are OPS (operations per second).
500000 rounds peer test.

storage | set | get | check | delete --------|-----|-----|-------|------- obj | 3,846,153 | 12,820,512 | 14,285,714 | 11,111,111 objV2 | 4,237,288 | 13,888,888 | 14,285,714 | 15,151,515 map | 3,816,793 | 55,555,555 | 50,000,000 | 7,246,376

The other thing that appeared to be a real showstopper in terms of performance - Date.now() calls, which been used in cache itself and in cache controller. So intermediate timestamp cache was implemented, performance impact of which you can see below.
And, furthermore, below you can see performance comparision with two most popular caching libs i know about.

Note: node-cache is in useClones: false, mode, but cache-base always copies it's values;

module | set | mset | get | mget | has | mhas -------|-----|------|-----|------|-----|----- Tagged Cache (w/o timestamp) (w/o tags) | '1,179,245' | '2,463,054' | '1,510,574' | '2,717,391' | '1,533,742' | '2,392,344' Tagged Cache (w/o timestamp) | '1,302,083' | '2,392,344' | '1,146,788' | '1,298,701' | '1,070,663' | '1,388,888' Tagged Cache (w/o tags) | '2,631,578' | '3,333,333' | '5,208,333' | '2,906,976' | '5,494,505' | '3,355,704' Tagged Cache | '2,976,190' | '3,378,378' | '1,845,018' | '1,436,781' | '1,976,284' | '1,529,051' node-cache | '284,900' | 'none' | '1,312,335' | '1,098,901' | 'none' | 'none' cache-base | '507,614' | 'none' | '892,857' | 'none' | '5,319,148' | 'none'

You can simply run performance tests on your own machine.

node benchmarks/storage.js
node benchmarks/cache.js

Install

npm i node-tagged-cache

Usage

import TaggedCache, {enableTimestampCache, disableTimestampCache} from "node-tagged-cache";
// default module's export is already created instance of cache with default options
// {
//  defaultTTL: 600000, // 10m
//  cleanupInterval: 60000, // 1m
// }

enableTimestampCache(); // this is not straight requirement but needed for performance improvement

TaggedCache.mset({
                    foo: "bar",
                    baz: "bax"
                },
                3600000, // 1h
                ["awesomeTag", "moreAwesomeTag"]);
TaggedCache.mget(["foo", "baz"]); // { foo: "bar", baz: "bax" }

TaggedCache.tags.drop("awesomeTag");
TaggedCache.mhas(["foo", "baz"]); // { foo: false, baz: false }

disableTimestampCache(); // before the script should exit;