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

prisma-caching

v0.1.0

Published

Automatic relation-aware caching for Prisma powered by BentoCache

Downloads

118

Readme

Prisma Cache

Automatic relation-aware caching for Prisma, powered by BentoCache.

Wraps your PrismaClient with a transparent proxy. Read operations are cached. Write operations run normally and automatically invalidate affected cache entries — including entries from related models, down to the field level.

No configuration required beyond setup. It reads your Prisma schema at runtime via DMMF.


Install

npm install prisma-caching bentocache
# or
pnpm add prisma-caching bentocache

Setup

import { withCache } from "prisma-caching";
import { PrismaClient } from "@prisma/client";
import { BentoCache, bentostore } from "bentocache";
import { memoryDriver } from "bentocache/drivers/memory";

const bento = new BentoCache({
  default: "memory",
  stores: {
    memory: bentostore().useL1Layer(memoryDriver()),
  },
});

const prisma = withCache(new PrismaClient(), bento, { ttl: 120 });

That's it. Use prisma exactly as you normally would.


Usage

Basic cached query

const users = await prisma.user.findMany({
  where: { active: true },
});

Cached automatically. Same args on the next call returns from cache.

Per-query options

const users = await prisma.user.findMany({
  where: { active: true },
  cache: {
    ttl: 30, // override TTL in seconds
    tags: ["active-users"], // custom tags for manual invalidation
    key: "active-users", // custom cache key
  },
});

Skip cache for a specific query

const fresh = await prisma.user.findMany({
  cache: { disable: true },
});

Writes invalidate automatically

await prisma.user.update({
  where: { id: 1 },
  data: { name: "Uanela" },
});
// All cached queries involving `user` are invalidated.
// Related model caches (e.g. posts that included user) are evaluated
// and only invalidated if they selected the mutated fields.

How invalidation works

When a write happens on a model:

  1. All cached entries tagged with that model are invalidated immediately.
  2. For related models, prisma-caching walks the stored query shapes and checks which fields were selected.
  3. If the mutated fields overlap with the selected fields, the entry is invalidated. Otherwise it is left untouched.

Example: a user.update that only changes birthday will not invalidate a cached post.findMany that only included user: { select: { name: true } }.

This logic is entirely automatic. It uses Prisma's runtime DMMF to build the relation graph — no manual model registration needed.


Global options

| Option | Type | Default | Description | | ------ | ---------- | ------- | ----------------------------------------- | | ttl | number | 60 | Default TTL in seconds for all queries | | tags | string[] | [] | Default tags applied to every cache entry |


Per-query cache options

| Option | Type | Description | | --------- | ---------- | ------------------------------------------- | | ttl | number | TTL in seconds, overrides global default | | tags | string[] | Additional tags for this entry | | key | string | Custom cache key, auto-generated if omitted | | disable | boolean | Skip cache entirely for this query |


Using Redis

import { BentoCache, bentostore } from "bentocache";
import { memoryDriver } from "bentocache/drivers/memory";
import { redisDriver } from "bentocache/drivers/redis";

const bento = new BentoCache({
  default: "multitier",
  stores: {
    multitier: bentostore()
      .useL1Layer(memoryDriver())
      .useL2Layer(
        redisDriver({ connection: { host: "localhost", port: 6379 } })
      ),
  },
});

const prisma = withCache(new PrismaClient(), bento);

prisma-caching delegates all storage, TTL, stampede protection, and grace periods to BentoCache. Any driver BentoCache supports works here.


Requirements

  • Node.js >= 18
  • Prisma >= 5
  • BentoCache >= 1.0

License

MIT