The package @yxx4c/prisma-redis-uncache has been deprecated. Please use prisma-extension-redis instead.
The prisma-redis-uncache
library complements the prisma-redis-cache library by providing a straightforward solution for selectively invalidating cached Prisma query results in a Redis/Dragonfly database. This library is essential for scenarios where real-time data updates or changes in the application's state require immediate cache invalidation to maintain data integrity.
🚀 If prisma-redis-uncache
proves helpful, consider giving it a star! ⭐ Star Me!
npm install @yxx4c/prisma-redis-uncache
yarn add @yxx4c/prisma-redis-uncache
pnpm add @yxx4c/prisma-redis-uncache
bun add @yxx4c/prisma-redis-uncache
import { PrismaClient } from '@prisma/client';
import { Redis } from 'ioredis';
import prismaUncache from '@yxx4c/prisma-redis-uncache';
// Create a Redis client
const redis = new Redis({
host: env.REDIS_HOST_NAME,
port: env.REDIS_PORT,
});
// Create a Prisma client instance
const prisma = new PrismaClient();
// Extend Prisma with the cache invalidation functionality provided by prisma-redis-uncache
const prismaWithUncache = prisma.$extends(prismaUncache({ redis }));
// Example: Update a user and invalidate related cache keys
prismaWithUncache.user.update({
where: { id },
data: { username },
uncache: {
uncacheKeys: [`user:${id}`, `user:${id}:post:*`], // Keys to be invalidated
hasPattern: true, // Use wildcard pattern for key matching
},
});
ioredis
- Selective Cache Invalidation: Easily uncache specific Prisma queries to ensure accurate and up-to-date data retrieval.
- Flexible Invalidation Strategies: Create various cache invalidation strategies to suit your application's needs.
- Programmatic Control: Integrate cache invalidation logic directly into your application code, offering fine-grained control over when and how cached data is invalidated.
With prisma-redis-uncache
, you can maintain the balance between performance optimization and data accuracy, ensuring that your application operates seamlessly even in dynamic environments with frequently changing data.
Enhance your Redis cache strategy with prisma-redis-cache. Seamlessly integrate query result caching to optimize the performance of your Prisma-based applications. Reduce latency and improve overall responsiveness, taking your Redis caching to new heights. Install and explore the features to enhance your existing Redis cache strategy.