Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yxx4c/cache-utils
Simple JavaScript utility for straightforward cache management
https://github.com/yxx4c/cache-utils
Last synced: 22 days ago
JSON representation
Simple JavaScript utility for straightforward cache management
- Host: GitHub
- URL: https://github.com/yxx4c/cache-utils
- Owner: yxx4c
- License: mit
- Created: 2024-01-05T03:23:35.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-20T20:00:04.000Z (5 months ago)
- Last Synced: 2024-09-01T09:21:54.817Z (4 months ago)
- Language: TypeScript
- Homepage: https://npmjs.com/@yxx4c/cache-utils
- Size: 88.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cache-utils
`cache-utils` is a versatile library designed to complement the [prisma-redis-cache](https://github.com/yxx4c/prisma-redis-cache) and [prisma-redis-uncache](https://github.com/yxx4c/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!](https://github.com/yxx4c/cache-utils)
## Installation
#### Using npm:
```bash
npm install @yxx4c/cache-utils
```#### Using yarn:
```bash
yarn add @yxx4c/cache-utils
```#### Using pnpm:
```bash
pnpm add @yxx4c/cache-utils
```#### Using bun:
```bash
bun add @yxx4c/cache-utils
```## Example
```javascript
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](https://github.com/yxx4c/cache-utils).