# @yxx4c/cache-utils

> Simple JavaScript utility for straightforward cache management.

Latest version **0.0.7** (published 2024-08-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @yxx4c/cache-utils
pnpm add @yxx4c/cache-utils
yarn add @yxx4c/cache-utils
bun add @yxx4c/cache-utils
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2024-08-20 |
| First published | 2024-01-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 31.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | caxxy |
| Maintainers | yxx4c |
| Keywords | utility, prisma, extension, redis, dragonflydb, cache, uncache |

## Links

- npm: https://www.npmjs.com/package/@yxx4c/cache-utils
- Repository: https://github.com/yxx4c/cache-utils
- Issues: https://github.com/yxx4c/cache-utils/issues
- npm.io page: https://npm.io/package/@yxx4c/cache-utils

## Dependencies (1)

- [lodash-es](https://npm.io/package/lodash-es.md) ^4.17.21

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.0.7 (latest) — 2024-08-20
- 0.0.6 — 2024-01-23
- 0.0.5 — 2024-01-12
- 0.0.4 — 2024-01-05
- 0.0.3 — 2024-01-05
- 0.0.2 — 2024-01-05
- 0.0.1 — 2024-01-05

## 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).

---
_Source: https://npm.io/package/@yxx4c/cache-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
