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 🙏

© 2026 – Pkg Stats / Ryan Hefner

redis-prisma-middleware

v1.6.0

Published

Readme

redis-prisma-middleware

Features

  • Cache Invalidation
  • Supports custom cache keys
  • cache and remove cache data automatically
  • Caching multiple Prisma models each with a specific cache time
  • Excluding certain Prisma models from being cached

Supported Node.js versions

The latest versions of the following Node.js versions are tested and supported.

  • 18

Default Cached Methods

Here is a list of all the Prisma methods that are currently cached by default in prisma-redis-middleware.

  • findUnique
  • findUniqueOrThrow
  • findFirst
  • findFirstOrThrow
  • findMany
  • count
  • aggregate
  • groupBy
  • findRaw
  • aggregateRaw

queryRaw is not cached as it's executed against the Prisma db itself and not a model. This Prisma middleware is used for caching queries based on the models that they are executed against.

Default remove cache Methods

Here is a list of all the Prisma methods that are currently cached by default in prisma-redis-middleware.

  • create
  • createMany
  • update
  • updateMany
  • upsert
  • delete
  • deleteMany
  • executeRawUnsafe

The cache data of the model which calls these functions will be deleted automatically

Quick Start

Install the package using npm:

npm i redis-prisma-middleware

Code Example

First you need an express middleware. Like [cacheHandler] and it will give you the data you want to cache, and if you add something to that model, it will use this middleware, if you add any new data to your model, the previous cache will be removed. And use the same middleware in the delete router so that when something is deleted, that cache data is removed.

const express = require("express");
const Router = express.Router();
const {
  createPost,
  getAllPost,
  deleteAllPost,
} = require("../controller/postController");
const { cacheHandler } = require("../middleware/common/cacheHandler");

Router.get("/post", cacheHandler, getUserPost);
Router.post("/post", cacheHandler, createPost); 
Router.delete("/post",cacheHandler, deletePost)

next

cacheHandler middleware code example

First you need to configure the Redis client. After that the prisma client needs to be configured. Then the [prismaRedisCacheHandler] function must be used inside the [cacheHandler] middleware. This function takes 2 parameters. The first parameter is if you want to set the invalidation time of a model, then you have to give any number above 0. This number will be counted in seconds. After that fixed time, the cache will be removed. And if 0 then no invalidation time will be set. And the second parameter is the redis client. You must pass these 2 parameters. [If you want to see where the data is coming from, pass (true )as the third parameter. This is an optional parameter

// redis configure
const redis = require("redis");
const redisUrl = "6379";
const client = redis.createClient(redisUrl);
const { prismaRedisCacheHandler } = require("redis-prisma-middleware");
client.connect();

// prisma configure
const { PrismaClient } = require("@prisma/client");
const db = new PrismaClient();

async function cacheHandler(req, res, next) {
  await prisma.$use(prismaRedisCacheHandler(0, client, true));
  next();
}

module.exports = { cacheHandler };