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

command-caching-fisherman

v1.0.1

Published

A command caching middleware, used to cache the result of a command

Downloads

9

Readme

Command Caching Fisherman

A command caching middleware, used to cache the result of a command. Copyright © 2017, Simon Sassi

Installation

npm install --save command-caching-fisherman

Usage

A sample example, it's caching the result of a command for 20 seconds. If you trigger the command test two times in less than 20 seconds, it will display the same timestamp

const fisherman = require("fisherman-discord.js")
var bot = new fisherman.Fisherman({ prefixes: ['test!'] }) // creating a new fisherman client, with the prefixe "test!"
const CommandCaching = require("command-caching-fisherman")
var caching = new CommandCaching({ cachemanOptions: { ttl: 20 } }) //Creating a new CommandCaching with a 20s default "Title to live"
//(ttl). The command result will be cached 20s if no ttl time is provided
bot.use(caching) //appending the middleware
var register = bot.createRegister('test', 'test') //creating a new register named "test"
console.log('registerCreated')
register.textCommand('test', null, function (req, res) { //creating a new command named "test", will be trigerred with test!test
  console.log("Command trigerred")
  res.sendAndCache("Date: " + Date.now()) //Send the current date. Result : "Date: 1501522374948"
})
bot.on('fisherCode', function (router, code, err) { //Handling fishercodes
  router.response.send('fisherCode ' + code + '\nError message: ' + err.message)
})
bot.init('_token_') //logging in the bot

Backend with redis, mongo, etc

Because this middleware is using cacheman, you can set a custom cache engine. By default cacheman uses the cacheman-memory engine.

See https://www.npmjs.com/package/cacheman

Api

req.sendAndCache(text[, messageOptions = {}, ttl])

text: The message to send

messageOptions: discord.js message options, available here

ttl: Time To Live in seconds

Disabling the cache feature on a command (it will not check if command result is in cache)

Just set the option disableCaching to true in the locales property of the command

register.textCommand('test', {locales: {disableCaching : true}}, function (req, res) {
[...]

Constructor options

| Name | Default value | Description | | ---- | ------ | ----- | | cacheName | "commandCache" | The key prefixe used by cacheman to store the command results | | cachemanOptions | {} | The cacheman's options, available here | keyGenerator | function (req) { return req.message.author.id + req.command.name } | Used to generate the cache key |