Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
/ prisma-redis-uncache Public archive

Prisma extension for selective cache invalidation in Redis and DragonflyDB

License

Notifications You must be signed in to change notification settings

yxx4c/prisma-redis-uncache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The package @yxx4c/prisma-redis-uncache has been deprecated. Please use prisma-extension-redis instead.

prisma-redis-uncache

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!

Installation

Using npm:
npm install @yxx4c/prisma-redis-uncache
Using yarn:
yarn add @yxx4c/prisma-redis-uncache
Using pnpm:
pnpm add @yxx4c/prisma-redis-uncache
Using bun:
bun add @yxx4c/prisma-redis-uncache

Example

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
  },
});

Dependencies

  • ioredis

Key Features

  • 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.

Elevate Redis Cache Performance with prisma-redis-cache

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.

About

Prisma extension for selective cache invalidation in Redis and DragonflyDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published