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

@quikc/express

v0.1.3

Published

This package contains middleware for integrating the caching library into your Express application.

Downloads

2

Readme

@quikc/express - express middileware for Quikc a NodeJS caching library

Table of contents

Introduction

@quikc/express is an express middleware for @quikc/core a Node.js caching library that supports multiple cache providers and pluggable lock providers. It is designed to be framework-agnostic and can be used in any Node.js application.

Installation

@quikc/express contains an express middleware that can be used to cache responses. You can install it by running the following command:

npm install @quikc/core @quikc/express
# or
yarn add @quikc/core @quikc/express

Usage

Basic usage

You can use @quikc/core package to create you cache instance with the desired cache provider and then use the @quikc/express middleware to cache your responses.

import express from 'express';
import { createStore } from '@quikc/core';
import { QuikcExpress } from '@quikc/express';

const app = express();

const cache = createStore('memory');

const quikc = new QuikcExpress({
    cache,
    getKey: req => req.path,
    shouldCache: (req, res) => req.method === 'GET' && res.statusCode === 200,
});

app.use(quikc.middleware);

app.get('/', (req, res) => {
    res.send('Hello World!');
});

app.listen(3000, () => {
    console.log('Example app listening on port 3000!');
});

Advanced usage

The QuickExpress class accepts the following options:

  • cache - The cache instance created using createStore function from @quikc/core package.

  • getKey - A function that accepts the express request object and returns the cache key.

  • shouldCache - A function that accepts the express request and response objects and returns a boolean indicating whether the response should be cached or not.

  • cacheFallback - A boolean indicating whether to serve the cached response if the request fails or not.

  • cacheFallbackTTL - The TTL of the cached response in seconds.

  • cacheOptions - An object containing the cache options. This object is passed to the cache provider.

    • ttl - The TTL of the cached response in seconds.
    • dependencies - An array of cache keys that the cached response depends on. If any of the dependencies is invalidated, the cached response will be invalidated as well.
    • priority - The priority of the cached response. The higher the priority, the more likely the cached response will be served.
    • lockTimeout - The lock timeout in milliseconds.
  • onError - A function that accepts the express request and response objects and is called when an error occurs while serving the cached response.

  • onHit - A function that accepts the express request and response objects and is called when a cached response is served.

  • onMiss - A function that accepts the express request and response objects and is called when a cached response is not found.

  • onSkip - A function that accepts the express request and response objects and is called when a response is not cached.

  • onStore - A function that accepts the express request and response objects and is called when a response is stored in the cache.

Contributing

Contributions are welcome! Please read the contributing guide for more information.

License

MIT