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

@abbudao/node-bloom-control

v1.4.0

Published

Bloom Control integration for Node. Used in pair with Bloom, the HTTP REST API caching middleware.

Downloads

5

Readme

node-bloom-control

Test and Build Build and Release NPM Downloads Buy Me A Coffee

Bloom Control integration for Node. Used in pair with Bloom, the HTTP REST API caching middleware.

Bloom Control lets you control your Bloom cache, from your NodeJS code. Purge API cache on-demand, whenever your API worker updates a database model or performs some action that require cached data to be invalidated.

🇫🇷 Crafted in Brest, France.

Who uses it?

👋 You use bloom-control and you want to be listed there? Contact me.

How to install?

Include bloom-control in your package.json dependencies.

Alternatively, you can run npm install bloom-control --save.

How to use?

1. Create the connection

node-bloom-control can be instanciated as such:

var BloomControl = require("bloom-control").BloomControl;

var bloomControl = new BloomControl({
  host  : "::1",  // Or '127.0.0.1' if you are still using IPv4
  port  : 8811,   // Default port is '8811'
  shard : 0       // Specify the Bloom shard to use, as \
                  //   a Bloom instance can host multiple cache shards, eg. for different API workers
}).connect({
  connected : function() {
    // Connected handler
    console.info("Bloom Control succeeded to connect to host.");
  },

  disconnected : function() {
    // Disconnected handler
    console.error("Bloom Control is now disconnected.");
  },

  timeout : function() {
    // Timeout handler
    console.error("Bloom Control connection timed out.");
  },

  retrying : function() {
    // Retry handler
    console.error("Trying to reconnect to Bloom Control...");
  },

  error : function(error) {
    // Failure handler
    console.error("Bloom Control failed to connect to host.", error);
  }
});

2. Purge cache collections

Use the same bloomControl instance to purge cache collections:

// Notice: all methods return 'true' if executed immediately, 'false' if deferred (ie. TCP socket disconnected)

// Purge cache for a given bucket (all authenticated users)
bloomControl.purgeBucket(`cache_bucket_id`, function(error) {
  // Handle purge errors here
});

// Purge cache for a multiple buckets at once (all authenticated users)
bloomControl.purgeBucket([
  `cache_bucket_id_1`,
  `cache_bucket_id_2`
], function(error) {
  // Handle purge errors here
});

// Purge all cache for a given authenticated user
// Notice: identifier and token can usually be found in your Basic Auth headers
bloomControl.purgeAuth(`auth_identifier`, `auth_token`, function(error) {
  // Handle purge errors here
});

// Purge all cache for multiple authenticated users at once
bloomControl.purgeAuth([
  [`auth_identifier_1`, `auth_token_1`],
  [`auth_identifier_2`, `auth_token_2`]
], function(error) {
  // Handle purge errors here
});

3. Listen for processed commands

In the event you need to debug the commands being executed (given the result, either NIL, OK, ERR or PONG), you can register a listener as:

// Listen for OK commands (ie. executed commands)
bloomControl.on("OK", function(command) {
  console.log("Command OK:", command);
});

// Listen for ERR commands (ie. failed commands)
bloomControl.on("ERR", function(command) {
  console.log("Command ERR:", command);
});

// Listen for NIL commands (ie. unknown commands, you won't need this)
bloomControl.on("NIL", function(command) {
  console.log("Command NIL:", command);
});

// Listen for PONG commands (ie. replies to pings)
bloomControl.on("PONG", function(command) {
  console.log("Command PONG:", command);
});

You can stop listening to events as such:

bloomControl.off("OK");
bloomControl.off("ERR");
bloomControl.off("NIL");
bloomControl.off("PONG");

Notice: only 1 handler can be registered at the same time for a given command result.

4. Test connection

You can test your connection to Bloom anytime by sending a ping:

bloomControl.ping(function(error) {
  // Handle ping errors here
});

The response to your ping will come on the event channel (register a listener for the PONG event).

Notice: pings are automatically sent to maintain the connection. You will get pong events periodically on the event channel, even if you never sent a ping.

5. Teardown connection

If you need to teardown an ongoing connection to Bloom, use:

// Returns: true if proceeding close, false if already closed
bloomControl.close(function(error) {
  // Handle close errors here
});

What is Bloom?

ℹ️ Wondering what Bloom is? Check out valeriansaliou/bloom.

How is it linked to Bloom?

node-bloom-control maintains a persistent TCP connection to the Bloom Control interface that's listening on your running Bloom instance. In case node-bloom-control gets disconnected from Bloom, it will retry to connect once the connection is established again. Pending cache purge requests that could not be transmitted to Bloom are stacked, up to a certain limit where further cache purge requests will be dropped and not stacked. Once the connection to Bloom Control is established again, stacked cache purge requests are transmitted to Bloom for processing.

You can configure the connection details of your Bloom instance when initializing node-bloom-control from your code; via the Bloom host and port.