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

raincache

v0.6.0

Published

A pluggable discord cache worker

Downloads

4

Readme

RainCache

A simple and modular discord caching library

Part of the WeatherStack

You want to use a shared cache for your discord bot ? Maybe MongoDB ? But Presences should be stored in redis ?

Then RainCache is the right tool for the job!

Cool things you can do with RainCache:

  • Store data received from discord in a configurable storage medium
  • Select the type of storage on a type level basis (e.g Channel, Presence, etc..)
  • Batteries included, RainCache can parse raw discord events and store the data accordingly
  • Easily customizable, you can write your own storage engine, connector or cache class

Documentation:

You can find the docs at https://daswolke.github.io/RainCache/

Installation:

To install RainCache, make sure that you have node 12 or higher and npm installed on your computer. Then run the following command in a terminal npm install raincache

Example:

const { RainCache, AmqpConnector, RedisStorageEngine } = require("raincache");
// Use the default options and create a new connector which isn't connected yet
const con = new AmqpConnector();
// Create a new uninitialized RainCache instance, set redis as the default storage engine,
// disable debugging mode and pass an inbound and an outbound connector to receive and forward events
const cache = new RainCache({
	storage: {
		default: new RedisStorageEngine({
			redisOptions: {
				host: "localhost"
			}
		})
	}, debug: false},
	con, /* THIS PARAM IS FOR SENDING DATA OFF SOMEWHERE ELSE AFTER PROCESSING IS DONE */);

const init = async () => {
	// initialize the cache, the connector and the database connection
	await cache.initialize();
};
// Declare an asynchronous init method
init().then(() => {
	console.log("Cache initialized");
}).catch(e => console.error(e));
// Run the init function

Small tricks and hints:

  • RainCache creates an entry on the user collection with an id of "self" when it processes the READY packet, this entry only contains an id and allows you to easily get the current user from the cache by looking up the id.

Notable Difference to normal caches

RainCache generally does not have any differences in comparison with general discord library caches, but there is one notable difference:

Presences are stored per user and not per guild

This means that you should make sure to fetch all users of a guild on startup of the gateway (by using guild member chunk), because you may have to deal with users that are not cached yet. This decision has the benefit,that you can safely ignore the presence_update event when you do not care about the status (online/offline, etc..) of a user. Apart from that it allows RainCache to minimize the storage usage a lot, since a user has one presence instead of x presences.


Object Binding

RainCache returns the data received as a cache object with additional properties found in the retrieved data. This way you can easily retrieve additional properties of received data (e.g. permission overwrites of a channel).

const cache = new RainCache(someOptions);
const channel = await cache.channel.get('channel id')
// The received object is a channel cache with the properties of the retrieved channel object (id, name, type, etc..) attached to it
const overwrites = await channel.permissionOverwrites.getIndexMembers()
//this would load all permission overwrites for the channel previously loaded

Indexing

RainCache uses indexing to allow you to easily get something like a list of all members of a server or similar, although, depending on the storage engine you use, it might not be needed. Whether indexing is used is up to the programmer of the storage engine you use. The Redis Storage Engine which is already shipped with RainCache does use indexing by creating a redis set per namespace with a collection of ids in it. This way you have a redis set containing something like a list of all members that are in a server available at guild.$guild_id.member