{"_id":"@1000ship/prisma-redis-middleware","_rev":"3-4a30558d425c3749225237875f7574ed","name":"@1000ship/prisma-redis-middleware","dist-tags":{"latest":"4.8.2"},"versions":{"4.8.0":{"name":"@1000ship/prisma-redis-middleware","version":"4.8.0","keywords":["prisma","redis","prisma-caching","redis-caching","prisma-middleware","caching"],"author":{"name":"A-J Roos","email":"asjas@hey.com"},"license":"Hippocratic-3.0","_id":"@1000ship/prisma-redis-middleware@4.8.0","maintainers":[{"name":"dantechun","email":"dev.1000ship@gmail.com"}],"homepage":"https://github.com/Asjas/prisma-redis-middleware#readme","bugs":{"url":"https://github.com/Asjas/prisma-redis-middleware/issues"},"dist":{"shasum":"f3f5b936ef61f712c1431fe0eaed0577ce94b736","tarball":"https://registry.npmjs.org/@1000ship/prisma-redis-middleware/-/prisma-redis-middleware-4.8.0.tgz","fileCount":18,"integrity":"sha512-12xPzxJUALTkBl3+eCMIWNs+q9ZSWlN1M8c8h/IHHiGJJScTD1bwuum1hFLNhWFsMPpSmd9R7PcZsgitTApnWA==","signatures":[{"sig":"MEYCIQCkXBg0aOdFJC5qQv4vyle6QKEMxOZi3+7ySE7/cqlxEgIhAMlLhcY922mDhv7bvNZJwD8az/UJv5TzlJeqmlE7QfVt","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":140348},"main":"./dist/index.js","husky":{"hooks":{"pre-commit":"npm run check-types && lint-staged && npm run build"}},"types":"./dist/index.d.ts","module":"./dist/prisma-redis-middleware.esm.js","source":"./src/index.ts","engines":{"npm":"^10.0.0","node":"^16.x || ^18.x || ^20.x"},"gitHead":"4f07b9250bdeeee126273842a0f0f18e7200ca34","scripts":{"size":"size-limit","test":"vitest run","build":"tsdx build","clean":"rimraf dist/ coverage/","start":"tsdx watch","format":"npm run prettier -- --write","analyze":"size-limit --why","prepare":"tsdx build","coverage":"c8 --reporter=lcov vitest run --coverage","prettier":"prettier --cache \"**/**/*.+(json|ts)\"","validate":"npm-run-all --parallel check-types check-format build","test:watch":"vitest -w","check-types":"tsc","check-format":"npm run prettier -- --list-different"},"_npmUser":{"name":"dantechun","email":"dev.1000ship@gmail.com"},"repository":{"url":"git+https://github.com/Asjas/prisma-redis-middleware.git","type":"git"},"size-limit":[{"path":"dist/prisma-redis-middleware.cjs.production.min.js","limit":"16 KB"},{"path":"dist/prisma-redis-middleware.esm.js","limit":"16 KB"}],"_npmVersion":"10.8.2","description":"Prisma Middleware for caching results of queries in Redis","directories":{},"lint-staged":{"**/**/*.+(ts)":["prettier --write","git add"]},"_nodeVersion":"20.18.3","dependencies":{"ioredis":"5.3.2","async-cache-dedupe":"2.0.0"},"_hasShrinkwrap":false,"devDependencies":{"c8":"8.0.1","tsdx":"0.14.1","husky":"8.0.3","tslib":"2.6.2","rimraf":"5.0.5","vitest":"0.34.6","prettier":"3.1.0","size-limit":"11.0.0","typescript":"5.3.2","lint-staged":"15.2.0","npm-run-all":"4.1.5","ioredis-mock":"8.9.0","@prisma/client":"5.6.0","@types/ioredis-mock":"8.2.5","@vitest/coverage-c8":"0.33.0","@vitest/coverage-v8":"0.34.6","@size-limit/preset-small-lib":"11.0.0","@ianvs/prettier-plugin-sort-imports":"4.1.1"},"_npmOperationalInternal":{"tmp":"tmp/prisma-redis-middleware_4.8.0_1740134641739_0.6142484857873598","host":"s3://npm-registry-packages-npm-production"}},"4.8.1":{"name":"@1000ship/prisma-redis-middleware","version":"4.8.1","keywords":["prisma","redis","prisma-caching","redis-caching","prisma-middleware","caching"],"author":{"name":"A-J Roos","email":"asjas@hey.com"},"license":"Hippocratic-3.0","_id":"@1000ship/prisma-redis-middleware@4.8.1","maintainers":[{"name":"dantechun","email":"dev.1000ship@gmail.com"}],"homepage":"https://github.com/Asjas/prisma-redis-middleware#readme","bugs":{"url":"https://github.com/Asjas/prisma-redis-middleware/issues"},"dist":{"shasum":"9a9a1b22afe29692ff7f449683dc427c08928441","tarball":"https://registry.npmjs.org/@1000ship/prisma-redis-middleware/-/prisma-redis-middleware-4.8.1.tgz","fileCount":18,"integrity":"sha512-htZ5bv1iLUuxU7LSzW1P/c76Aod1eELTnVxqBqJn2/HduEzimM2RAjPHt82uEtXUnll7EZlt+8VJ4fFAhOINfA==","signatures":[{"sig":"MEUCIQClz0gK3cN22/BHJ80BCnNSJXFrSFyX3ci/Rg50+TYtLwIgfvIAqT8vF1M0yFxBvUCBfRGCGDJSqA4JsJwVGtf+UAw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":140348},"main":"./dist/index.js","husky":{"hooks":{"pre-commit":"npm run check-types && lint-staged && npm run build"}},"types":"./dist/index.d.ts","module":"./dist/prisma-redis-middleware.esm.js","source":"./src/index.ts","engines":{"npm":"^10.0.0","node":"^16.x || ^18.x || ^20.x"},"gitHead":"1d3537ff6feac20751672b026b081ce2cdde348a","scripts":{"size":"size-limit","test":"vitest run","build":"tsdx build","clean":"rimraf dist/ coverage/","start":"tsdx watch","format":"npm run prettier -- --write","analyze":"size-limit --why","prepare":"tsdx build","coverage":"c8 --reporter=lcov vitest run --coverage","prettier":"prettier --cache \"**/**/*.+(json|ts)\"","validate":"npm-run-all --parallel check-types check-format build","test:watch":"vitest -w","check-types":"tsc","check-format":"npm run prettier -- --list-different"},"_npmUser":{"name":"dantechun","email":"dev.1000ship@gmail.com"},"repository":{"url":"git+https://github.com/Asjas/prisma-redis-middleware.git","type":"git"},"size-limit":[{"path":"dist/prisma-redis-middleware.cjs.production.min.js","limit":"16 KB"},{"path":"dist/prisma-redis-middleware.esm.js","limit":"16 KB"}],"_npmVersion":"10.8.2","description":"Prisma Middleware for caching results of queries in Redis","directories":{},"lint-staged":{"**/**/*.+(ts)":["prettier --write","git add"]},"_nodeVersion":"20.18.3","dependencies":{"ioredis":"5.3.2","async-cache-dedupe":"2.0.0"},"_hasShrinkwrap":false,"devDependencies":{"c8":"8.0.1","tsdx":"0.14.1","husky":"8.0.3","tslib":"2.6.2","rimraf":"5.0.5","vitest":"0.34.6","prettier":"3.1.0","size-limit":"11.0.0","typescript":"5.3.2","lint-staged":"15.2.0","npm-run-all":"4.1.5","ioredis-mock":"8.9.0","@prisma/client":"6.4.1","@types/ioredis-mock":"8.2.5","@vitest/coverage-c8":"0.33.0","@vitest/coverage-v8":"0.34.6","@size-limit/preset-small-lib":"11.0.0","@ianvs/prettier-plugin-sort-imports":"4.1.1"},"_npmOperationalInternal":{"tmp":"tmp/prisma-redis-middleware_4.8.1_1740134830798_0.4793323463570296","host":"s3://npm-registry-packages-npm-production"}},"4.8.2":{"name":"@1000ship/prisma-redis-middleware","author":{"name":"A-J Roos","email":"asjas@hey.com"},"version":"4.8.2","description":"Prisma Middleware for caching results of queries in Redis","license":"Hippocratic-3.0","main":"./dist/index.js","types":"./dist/index.d.ts","source":"./src/index.ts","module":"./dist/prisma-redis-middleware.esm.js","scripts":{"start":"tsdx watch","build":"tsdx build","clean":"rimraf dist/ coverage/","prepare":"tsdx build","test":"vitest run","test:watch":"vitest -w","coverage":"c8 --reporter=lcov vitest run --coverage","check-types":"tsc","prettier":"prettier --cache \"**/**/*.+(json|ts)\"","format":"npm run prettier -- --write","check-format":"npm run prettier -- --list-different","validate":"npm-run-all --parallel check-types check-format build","size":"size-limit","analyze":"size-limit --why"},"dependencies":{"async-cache-dedupe":"2.0.0","ioredis":"5.3.2"},"devDependencies":{"@ianvs/prettier-plugin-sort-imports":"4.1.1","@prisma/client":"6.4.1","@size-limit/preset-small-lib":"11.0.0","@types/ioredis-mock":"8.2.5","@vitest/coverage-c8":"0.33.0","@vitest/coverage-v8":"0.34.6","c8":"8.0.1","husky":"8.0.3","ioredis-mock":"8.9.0","lint-staged":"15.2.0","npm-run-all":"4.1.5","prettier":"3.1.0","rimraf":"5.0.5","size-limit":"11.0.0","tsdx":"0.14.1","tslib":"2.6.2","typescript":"5.3.2","vitest":"0.34.6"},"husky":{"hooks":{"pre-commit":"npm run check-types && lint-staged && npm run build"}},"lint-staged":{"**/**/*.+(ts)":["prettier --write","git add"]},"size-limit":[{"path":"dist/prisma-redis-middleware.cjs.production.min.js","limit":"16 KB"},{"path":"dist/prisma-redis-middleware.esm.js","limit":"16 KB"}],"engines":{"node":">=16.x","npm":">=10.0.0"},"repository":{"type":"git","url":"git+https://github.com/Asjas/prisma-redis-middleware.git"},"keywords":["prisma","redis","prisma-caching","redis-caching","prisma-middleware","caching"],"bugs":{"url":"https://github.com/Asjas/prisma-redis-middleware/issues"},"homepage":"https://github.com/Asjas/prisma-redis-middleware#readme","packageManager":"yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e","_id":"@1000ship/prisma-redis-middleware@4.8.2","gitHead":"1d3537ff6feac20751672b026b081ce2cdde348a","_nodeVersion":"22.16.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-Lwi1nVnse7lm4a0ptY/2P2vfdT6nzCC6kWv4rkTmGR25au0KzTs0+TzIXc9HdG793RqVJfKngDDMxdB1Iga/lQ==","shasum":"0b95e2806d9138928c08520e939cbf1f624ac3ed","tarball":"https://registry.npmjs.org/@1000ship/prisma-redis-middleware/-/prisma-redis-middleware-4.8.2.tgz","fileCount":18,"unpackedSize":140504,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIEIL2DpN3T++5NrL88N3CusC8bpyO7//H1p1yKybhxZkAiEA78VuLn1IHm9IO4onxc3QODsGYY5MsXygpK2oSyYa5tg="}]},"_npmUser":{"name":"dantechun","email":"dev.1000ship@gmail.com"},"directories":{},"maintainers":[{"name":"dantechun","email":"dev.1000ship@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/prisma-redis-middleware_4.8.2_1757480843316_0.7422548814474166"},"_hasShrinkwrap":false}},"time":{"created":"2025-02-21T10:44:01.634Z","modified":"2025-09-10T05:07:23.738Z","4.8.0":"2025-02-21T10:44:01.891Z","4.8.1":"2025-02-21T10:47:10.966Z","4.8.2":"2025-09-10T05:07:23.524Z"},"bugs":{"url":"https://github.com/Asjas/prisma-redis-middleware/issues"},"author":{"name":"A-J Roos","email":"asjas@hey.com"},"license":"Hippocratic-3.0","homepage":"https://github.com/Asjas/prisma-redis-middleware#readme","keywords":["prisma","redis","prisma-caching","redis-caching","prisma-middleware","caching"],"repository":{"type":"git","url":"git+https://github.com/Asjas/prisma-redis-middleware.git"},"description":"Prisma Middleware for caching results of queries in Redis","maintainers":[{"name":"dantechun","email":"dev.1000ship@gmail.com"}],"readme":"# `prisma-redis-middleware`\n\n[![License: Hippocratic 3.0](https://img.shields.io/badge/License-Hippocratic_3.0-lightgrey.svg)](https://firstdonoharm.dev)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![npm version](https://badge.fury.io/js/prisma-redis-middleware.svg)](https://badge.fury.io/js/prisma-redis-middleware)\n[![codecov](https://codecov.io/gh/Asjas/prisma-redis-middleware/branch/main/graph/badge.svg?token=6F6DDOSRK8)](https://codecov.io/gh/Asjas/prisma-redis-middleware)\n[![Main WorkFlow](https://github.com/Asjas/prisma-redis-middleware/actions/workflows/main.yml/badge.svg)](https://github.com/Asjas/prisma-redis-middleware/actions/workflows/main.yml)\n[![CodeQL WorkFlow](https://github.com/Asjas/prisma-redis-middleware/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Asjas/prisma-redis-middleware/actions/workflows/codeql-analysis.yml)\n[![Library code size](https://github.com/Asjas/prisma-redis-middleware/actions/workflows/size.yml/badge.svg)](https://github.com/Asjas/prisma-redis-middleware/actions/workflows/size.yml)\n\nThis is a Prisma middleware used for caching and storing of Prisma queries in Redis (uses an in-memory LRU cache as\nfallback storage).\n\nUses [async-cache-dedupe](https://github.com/mcollina/async-cache-dedupe).\n\n## Features\n\n- Cache Invalidation\n- Supports custom cache keys\n- Cache persistance with Redis (uses an in-memory LRU cache as fallback)\n- Caching multiple Prisma models each with a specific cache time\n- Excluding certain Prisma models from being cached\n- Excluding certain Prisma queries from being cached across all models\n\n## Supported Node.js versions\n\nThe latest versions of the following Node.js versions are tested and supported.\n\n- 16\n- 18\n\n## Default Cached Methods\n\nHere is a list of all the Prisma methods that are currently cached by default in `prisma-redis-middleware`.\n\n- findUnique\n- findUniqueOrThrow\n- findFirst\n- findFirstOrThrow\n- findMany\n- count\n- aggregate\n- groupBy\n- findRaw\n- aggregateRaw\n\n`queryRaw` is not cached as it's executed against the Prisma db itself and not a model. This Prisma middleware is used\nfor caching queries based on the models that they are executed against.\n\n## Quick Start\n\nInstall the package using `npm`:\n\n```sh\nnpm i --save-exact prisma-redis-middleware\n```\n\n_You will also need to install and configure an external dependency for `Redis` (for example: `ioredis` or one that uses\na similar API) if you don't already have a Redis Client in your project._\n\n```sh\nnpm i --save-exact ioredis @types/ioredis\n```\n\n## Code Example (ESM / Import)\n\n```mjs\nimport Prisma from \"prisma\";\nimport { PrismaClient } from \"@prisma/client\";\nimport { createPrismaRedisCache } from \"prisma-redis-middleware\";\nimport Redis from \"ioredis\";\n\nconst redis = new Redis(); // Uses default options for Redis connection\n\nconst prisma = new PrismaClient();\n\nconst cacheMiddleware: Prisma.Middleware = createPrismaRedisCache({\n  models: [\n    { model: \"User\", excludeMethods: [\"findMany\"] },\n    { model: \"Post\", cacheTime: 180, cacheKey: \"article\" },\n  ],\n  storage: { type: \"redis\", options: { client: redis, invalidation: { referencesTTL: 300 }, log: console } },\n  cacheTime: 300,\n  excludeModels: [\"Product\", \"Cart\"],\n  excludeMethods: [\"count\", \"groupBy\"],\n  onHit: (key) => {\n    console.log(\"hit\", key);\n  },\n  onMiss: (key) => {\n    console.log(\"miss\", key);\n  },\n  onError: (key) => {\n    console.log(\"error\", key);\n  },\n});\n\nprisma.$use(cacheMiddleware);\n```\n\n## Code Example (Common JS / Require)\n\n```js\nconst Prisma = require(\"prisma\");\nconst { PrismaClient } = require(\"@prisma/client\");\nconst { createPrismaRedisCache } = require(\"prisma-redis-middleware\");\n\nconst prisma = new PrismaClient();\n\nconst cacheMiddleware: Prisma.Middleware = createPrismaRedisCache({\n  models: [\n    { model: \"User\", cacheTime: 60 },\n    { model: \"Post\", cacheTime: 180 },\n  ],\n  storage: { type: \"memory\", options: { invalidation: true, log: console } },\n  cacheTime: 300,\n  onHit: (key) => {\n    console.log(\"hit\", key);\n  },\n  onMiss: (key) => {\n    console.log(\"miss\", key);\n  },\n  onError: (key) => {\n    console.log(\"error\", key);\n  },\n});\n\nprisma.$use(cacheMiddleware);\n```\n\n## API\n\n### `createPrismaRedisCache(opts)`\n\nOptions:\n\n- `onDedupe`: (optional) a function that is called every time a query is deduped.\n- `onError`: (optional) a function that is called every time there is a cache error.\n- `onHit`: (optional) a function that is called every time there is a hit in the cache.\n- `onMiss`: (optional) a function that is called every time the result is not in the cache.\n- `cacheTime`: (optional) (number) the default time (in seconds) to use for models that don't have a `cacheTime` value set.\n  Default is 0.\n- `excludeModels`: (optional) (string) an array of models to exclude from being cached.\n- `excludeMethods`: (optional) (string) an array of Prisma methods to exclude from being cached for all models.\n- `models`: (optional) an array of Prisma models. Models options are:\n\n  - `model`: (required) string.\n  - `cacheKey`: (optional) string. Default is the model value.\n  - `cacheTime`: (optional) number (in seconds).\n  - `excludeMethods`: (optional) (string) an array of Prisma methods to exclude from being cached for this model.\n  - `invalidateRelated`: (optional) (string) an array of Prisma models to invalidate when mutating this model.\n\n    Example:\n\n    ```js\n    createPrismaRedisCache({\n      models: [\n        { model: \"User\", cacheTime: 60, invalidateRelated: [\"Post\"] },\n        { model: \"Post\", cacheKey: \"article\", excludeMethods: [\"findFirst\"] },\n      ],\n    });\n    ```\n\n- `storage`: (optional) the storage options; default is `{ type: \"memory\" }`. Storage options are:\n\n  - `type`: `memory` (default) or `redis`\n  - `options`: by storage type\n\n    - for `memory` type\n\n      - `size`: (optional) maximum number of items to store in the cache. Default is `1024`.\n      - `invalidation`: (optional) enable invalidation. Default is disabled.\n      - `log`: (optional) logger instance `pino` compatible, or `console`, default is disabled.\n\n      Example:\n\n      ```js\n      createPrismaRedisCache({\n        storage: { type: \"memory\", options: { size: 2048 }, log: console },\n      });\n      ```\n\n    - for `redis` type\n\n      - `client`: a redis client instance, mandatory. Should be an `ioredis` client or compatible.\n      - `invalidation`: (optional) enable invalidation. Default is disabled.\n      - `invalidation.referencesTTL`: (optional) references TTL in seconds, it means how long the references are alive;\n        it should be set at the maximum of all the caches ttl.\n      - `log`: (optional) logger instance `pino` compatible, or `console`, default is disabled.\n\n      Example\n\n      ```js\n      const redis = new Redis();\n\n      createPrismaRedisCache({\n        storage: {\n          type: \"redis\",\n          options: { client: redis, invalidation: { referencesTTL: 60 }, log: console },\n        },\n      });\n      ```\n\n- `transformer`: (optional) the transformer to used to serialize and deserialize the cache entries. It must be an object\n  with the following methods:\n\n  - `serialize`: a function that receives the result of the original function and returns a serializable object.\n  - `deserialize`: a function that receives the serialized object and returns the original result.\n\n  - Default is `undefined`, so the default transformer is used.\n\n    Example\n\n    ```js\n    import superjson from \"superjson\";\n\n    createPrismaRedisCache({\n      transformer: {\n        serialize: (result) => superjson.serialize(result),\n        deserialize: (serialized) => superjson.deserialize(serialized),\n      },\n    });\n    ```\n\n## Debugging\n\nYou can pass functions for `onMiss`, `onHit`, `onError` and `onDedupe` to `createPrismaRedisCache` which can then be\nused to debug whether a Prisma query is being cached or not.\n\nYou can also pass a custom `log` (pino or console) to the `storage` option and `async-cache-dedupe` will print debug\ninfo as it queries, sets, expires and invalidates the cache. Note that the `log` option can print out very verbose\noutput.\n","readmeFilename":"README.md"}