@nexusts/cache 0.9.9 → 0.9.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +50 -8
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # @nexusts/cache
2
2
 
3
- > **NexusTS** — Bun-native fullstack framework
3
+ > **NexusTS Cache** — Application cache with memory, Redis, and Drizzle backends. Tag-based invalidation, TTL, and decorator support.
4
4
 
5
- ## Description
5
+ ## Features
6
6
 
7
- Application cache (memory / Drizzle backends).
8
-
9
- Tagged caching with LRU eviction (memory) or shared Drizzle storage. Group keys by tag and invalidate them together.
7
+ - **3 backends**: Memory (default), Redis, Drizzle
8
+ - **Tag-based invalidation** — group keys by tag and bust them together
9
+ - **TTL** per-key or default expiry
10
+ - **Decorators** — `@Cacheable` / `@CacheInvalidate` (dual-mode: standard + legacy)
11
+ - **Field injection** — `@Inject(CacheService.TOKEN) declare cache: CacheService`
10
12
 
11
13
  ## Install
12
14
 
@@ -28,13 +30,53 @@ bun add @nexusts/cache
28
30
 
29
31
  **None.** No external dependencies. The memory and Drizzle backends are bundled; the Drizzle backend uses `@nexusts/drizzle` if installed.
30
32
 
31
- ## Usage
33
+ ## Quick start
34
+
35
+ ```bash
36
+ bun add @nexusts/cache
37
+ ```
38
+
39
+ ```typescript
40
+ import { CacheService, CacheModule } from "@nexusts/cache";
41
+ import { Inject, Module } from "@nexusts/core";
42
+
43
+ @Module({
44
+ imports: [CacheModule.forRoot({ defaultTtl: 300 })],
45
+ })
46
+ class AppModule {}
47
+
48
+ class UserService {
49
+ @Inject(CacheService.TOKEN) declare cache: CacheService;
50
+
51
+ async getUser(id: string) {
52
+ return this.cache.wrap(`user:${id}`, () => this.db.findUser(id), 60);
53
+ }
54
+ }
55
+ ```
56
+
57
+ ## Backends
58
+
59
+ | Backend | Use case | Setup |
60
+ |---------|----------|-------|
61
+ | `memory` | Single-pod, fast | Default (no extra deps) |
62
+ | `redis` | Multi-pod, shared cache | `backend: 'redis'` + `@nexusts/redis` |
63
+ | `drizzle` | Persistent, DB-backed | `store: new DrizzleCacheStore(db)` |
64
+
65
+ ## Decorators
32
66
 
33
67
  ```typescript
34
- import { /* public API */ } from "@nexusts/cache";
68
+ import { Cacheable, CacheInvalidate } from "@nexusts/cache"
69
+
70
+ class PostService {
71
+ @Cacheable("post", (id: string) => id, 60)
72
+ async findById(id: string) { /* ... */ }
73
+
74
+ @CacheInvalidate("post", (id: string) => id)
75
+ async deleteById(id: string) { /* ... */ }
76
+ }
35
77
  ```
36
78
 
37
- See the [user guide](../../docs/user-guide/cache.md) and the [example app](../../examples/) for a working demo.
79
+ See the [user guide](../../docs/user-guide/cache.md) and the [example app](../../examples/14-cache/) for a working demo.
38
80
 
39
81
  ## License
40
82
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexusts/cache",
3
- "version": "0.9.9",
3
+ "version": "0.9.10",
4
4
  "description": "Application cache (memory / Redis / Drizzle backends)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@nexusts/core": "^0.9.9"
29
+ "@nexusts/core": "^0.9.10"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@nexusts/redis": ">=0.7.0"