@tc-libs/app-cache 3.5.0 → 3.6.1

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 +91 -11
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,11 +1,91 @@
1
- # app-cache
2
-
3
- This library was generated with [Nx](https://nx.dev).
4
-
5
- ## Building
6
-
7
- Run `nx build app-cache` to build the library.
8
-
9
- ## Running unit tests
10
-
11
- Run `nx test app-cache` to execute the unit tests via [Jest](https://jestjs.io).
1
+ # @tc-libs/app-cache
2
+
3
+ Astrazione cache per NestJS basata su `@nestjs/cache-manager`. Supporta due modalita:
4
+
5
+ - cache in-memory quando `enabled` e `false`
6
+ - cache Redis quando `enabled` e `true`
7
+
8
+ Il package viene usato soprattutto dai repository Mongo del monorepo per cacheare query e count.
9
+
10
+ ## Registrazione
11
+
12
+ ```ts
13
+ AppCacheModule.register(
14
+ true,
15
+ {
16
+ enabled: true,
17
+ ttl: 60,
18
+ server: {
19
+ host: '127.0.0.1',
20
+ port: 6379,
21
+ },
22
+ },
23
+ true,
24
+ );
25
+ ```
26
+
27
+ Versione async:
28
+
29
+ ```ts
30
+ AppCacheModule.registerAsync(
31
+ true,
32
+ {
33
+ imports: [ConfigModule],
34
+ inject: [ConfigService],
35
+ useFactory: async (config: ConfigService) => ({
36
+ enabled: true,
37
+ ttl: 60,
38
+ server: {
39
+ host: config.getOrThrow<string>('REDIS_HOST'),
40
+ port: config.getOrThrow<number>('REDIS_PORT'),
41
+ },
42
+ }),
43
+ },
44
+ true,
45
+ );
46
+ ```
47
+
48
+ ## Servizio esportato
49
+
50
+ `AppCacheService` espone i metodi usati dal resto del monorepo:
51
+
52
+ - `getCachedDataByQuery(functionName, find, options)`
53
+ - `getCachedDataByKey(key)`
54
+ - `saveToCache(key, data, options)`
55
+
56
+ Lato repository il pattern tipico e:
57
+
58
+ ```ts
59
+ const { data, key } = await this.cache.getCachedDataByQuery(
60
+ 'findOne',
61
+ find,
62
+ options,
63
+ );
64
+
65
+ if (data) return data;
66
+
67
+ this.cache.saveToCache(key, result, options);
68
+ ```
69
+
70
+ ## Note operative
71
+
72
+ - La chiave cache viene derivata da `functionName`, filtro e opzioni tramite hash SHA1 Base64.
73
+ - La cache viene usata solo se il modulo e abilitato e l'operazione passa `options.caching.enabled`.
74
+ - Se vuoi una chiave custom puoi passare `options.caching.key`.
75
+
76
+ ## Export pubblici
77
+
78
+ ```ts
79
+ import {
80
+ AppCacheModule,
81
+ AppCacheService,
82
+ ICachingOptions,
83
+ } from '@tc-libs/app-cache';
84
+ ```
85
+
86
+ ## Sviluppo
87
+
88
+ ```bash
89
+ nx build app-cache
90
+ nx test app-cache
91
+ ```
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@tc-libs/app-cache",
3
- "version": "3.5.0",
3
+ "version": "3.6.1",
4
4
  "dependencies": {
5
- "@tc-libs/helper": "3.5.0",
5
+ "@tc-libs/helper": "3.6.1",
6
6
  "@nestjs/common": "^11.0.12",
7
7
  "@nestjs/cache-manager": "^3.0.1",
8
8
  "cache-manager-redis-store": "^3.0.1",