0.0.6 ā€¢ Published 4 months ago

@yxx4c/cache-utils v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

cache-utils

cache-utils is a versatile library designed to complement the prisma-redis-cache and prisma-redis-uncache libraries. It offers general-purpose functions for efficient Redis/DragonflyDB database maintenance.

šŸš€ If cache-utils proves helpful, consider giving it a star! ā­ Star Me!

Installation

Using npm:

npm install @yxx4c/cache-utils

Using yarn:

yarn add @yxx4c/cache-utils

Using pnpm:

pnpm add @yxx4c/cache-utils

Using bun:

bun add @yxx4c/cache-utils

Example

import { getCacheKey, getCacheKeyPattern } from '@yxx4c/cache-utils';

// ...Extend Prisma with prisma-redis-cache

// Query a user and cache the result with custom configuration
prismaWithCache.user.findUnique({
  where: { id },
  cache: { ttl: 5, key: getCacheKey([{ prisma: 'User' }, { userId: id }]) },
});

// ...Extend Prisma with prisma-redis-uncache

// Example: Update a user and invalidate related cache keys
prismaWithUncache.user.update({
  where: { id },
  data: { username },
  uncache: {
    uncacheKeys: [
      getCacheKey([{ prisma: 'User' }, { userId: id }]),
      getCacheKeyPattern([{ prisma: '*' }, { userId: id }]), // Pattern matching under a specific key, eg: prisma:*:userId:1234
      getCacheKeyPattern([{ prisma: 'Post' }, { userId: id }, { glob: '*' }]), // Utilizing the key 'glob' to create a wildcard region, eg: prisma:post:userId:1234:*
    ],
    hasPattern: true,
  },
});

Integrate cache-utils seamlessly with prisma-redis-cache and prisma-redis-uncache for comprehensive Redis/DragonflyDB database management. If you find value in this library, show your support by giving it a star on GitHub.

0.0.6

4 months ago

0.0.5

4 months ago

0.0.4

4 months ago

0.0.3

4 months ago

0.0.2

4 months ago

0.0.1

4 months ago