@nathapp/nestjs-cache 2.1.0-rc.0 → 2.1.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 (95) hide show
  1. package/CLAUDE.md +149 -0
  2. package/README.md +330 -420
  3. package/TODO.md +56 -0
  4. package/dist/enum/strategy.enum.js.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/inteceptor/index.d.ts +1 -2
  9. package/dist/inteceptor/index.js +1 -2
  10. package/dist/inteceptor/index.js.map +1 -1
  11. package/dist/interceptor/cache-invalidate.interceptor.js.map +1 -0
  12. package/dist/{inteceptor → interceptor}/cache.interceptor.js +9 -3
  13. package/dist/interceptor/cache.interceptor.js.map +1 -0
  14. package/dist/interceptor/index.d.ts +2 -0
  15. package/dist/interceptor/index.js +19 -0
  16. package/dist/interceptor/index.js.map +1 -0
  17. package/dist/interface/cache-invalidate.interface.d.ts +8 -0
  18. package/dist/interface/enhanced-cache-options.interface.d.ts +16 -0
  19. package/dist/interface/health.interface.d.ts +19 -0
  20. package/dist/interface/health.interface.js +3 -0
  21. package/dist/interface/health.interface.js.map +1 -0
  22. package/dist/interface/index.d.ts +2 -0
  23. package/dist/interface/index.js +2 -0
  24. package/dist/interface/index.js.map +1 -1
  25. package/dist/interface/metrics.interface.d.ts +17 -0
  26. package/dist/interface/metrics.interface.js +3 -0
  27. package/dist/interface/metrics.interface.js.map +1 -0
  28. package/dist/module/cache-invalidate.provider.js +5 -0
  29. package/dist/module/cache-invalidate.provider.js.map +1 -1
  30. package/dist/module/cache-module.interface.d.ts +1 -0
  31. package/dist/module/cache.module.d.ts +2 -1
  32. package/dist/module/cache.module.js +7 -3
  33. package/dist/module/cache.module.js.map +1 -1
  34. package/dist/module/cache.provider.js +69 -1
  35. package/dist/module/cache.provider.js.map +1 -1
  36. package/dist/provider/cacheable.provider.d.ts +3 -0
  37. package/dist/provider/cacheable.provider.js +120 -35
  38. package/dist/provider/cacheable.provider.js.map +1 -1
  39. package/dist/service/cache-invalidate.factory.js.map +1 -1
  40. package/dist/service/cache-invalidate.manager.d.ts +4 -3
  41. package/dist/service/cache-invalidate.manager.js +8 -5
  42. package/dist/service/cache-invalidate.manager.js.map +1 -1
  43. package/dist/service/cache-manager.d.ts +39 -8
  44. package/dist/service/cache-manager.js +579 -71
  45. package/dist/service/cache-manager.js.map +1 -1
  46. package/dist/service/cache-provider.js +3 -6
  47. package/dist/service/cache-provider.js.map +1 -1
  48. package/dist/service/cache-tag-registry.d.ts +30 -0
  49. package/dist/service/cache-tag-registry.js +100 -0
  50. package/dist/service/cache-tag-registry.js.map +1 -0
  51. package/dist/service/index.d.ts +1 -0
  52. package/dist/service/index.js +1 -0
  53. package/dist/service/index.js.map +1 -1
  54. package/dist/service/redis-cache-invalidate.manager.d.ts +9 -1
  55. package/dist/service/redis-cache-invalidate.manager.js +107 -55
  56. package/dist/service/redis-cache-invalidate.manager.js.map +1 -1
  57. package/dist/service/redis-pattern-invalidation.js +4 -0
  58. package/dist/service/redis-pattern-invalidation.js.map +1 -1
  59. package/dist/utils/cache-key.utils.d.ts +3 -0
  60. package/dist/utils/cache-key.utils.js +34 -2
  61. package/dist/utils/cache-key.utils.js.map +1 -1
  62. package/dist/utils/config-validation.d.ts +2 -0
  63. package/dist/utils/config-validation.js +57 -0
  64. package/dist/utils/config-validation.js.map +1 -0
  65. package/dist/utils/deprecation.d.ts +1 -0
  66. package/dist/utils/deprecation.js +13 -2
  67. package/dist/utils/deprecation.js.map +1 -1
  68. package/dist/utils/index.d.ts +3 -0
  69. package/dist/utils/index.js +3 -0
  70. package/dist/utils/index.js.map +1 -1
  71. package/dist/utils/redis-uri.utils.d.ts +9 -0
  72. package/dist/utils/redis-uri.utils.js +62 -0
  73. package/dist/utils/redis-uri.utils.js.map +1 -0
  74. package/dist/utils/validation.d.ts +10 -0
  75. package/dist/utils/validation.js +39 -0
  76. package/dist/utils/validation.js.map +1 -0
  77. package/docker-compose.e2e.yml +16 -0
  78. package/docs/CACHEOBLESYNC-MIGRATION-PLAN.md +55 -0
  79. package/docs/CODE-REVIEW-2026-02-10-v2.md +134 -0
  80. package/docs/CODE-REVIEW-2026-02-10.md +142 -0
  81. package/docs/CODE_REVIEW.md +356 -0
  82. package/docs/FINAL-CODE-REVIEW-2026-02-10.md +312 -0
  83. package/docs/IMPLEMENTATION_PLAN.md +1045 -0
  84. package/docs/IMPLEMENTATION_PLAN_V2.md +201 -0
  85. package/docs/IMPLEMENTATION_PLAN_V3.md +169 -0
  86. package/docs/IMPLEMENTATION_TASKS.md +1090 -0
  87. package/docs/PHASE3_COVERAGE_TASKS.md +266 -0
  88. package/docs/TAG-BASED-INVALIDATION-PLAN.md +367 -0
  89. package/docs/UNIFIED-INVALIDATE-PLAN.md +229 -0
  90. package/package.json +13 -6
  91. package/dist/inteceptor/cache-invalidate.interceptor.js.map +0 -1
  92. package/dist/inteceptor/cache.interceptor.js.map +0 -1
  93. /package/dist/{inteceptor → interceptor}/cache-invalidate.interceptor.d.ts +0 -0
  94. /package/dist/{inteceptor → interceptor}/cache-invalidate.interceptor.js +0 -0
  95. /package/dist/{inteceptor → interceptor}/cache.interceptor.d.ts +0 -0
package/CLAUDE.md ADDED
@@ -0,0 +1,149 @@
1
+ # @nathapp/nestjs-cache Development Guide
2
+
3
+ ## Package Overview
4
+
5
+ NestJS caching module supporting both legacy (`@nestjs/cache-manager`) and enhanced (`cacheable`) modes with multi-tier caching capabilities.
6
+
7
+ ## Architecture
8
+
9
+ ```
10
+ lib/
11
+ ├── constant/ # Injection tokens, defaults
12
+ ├── decorator/ # @CacheReqOptions, @CacheInvalidate
13
+ ├── enum/ # CacheStrategy, InvalidateStrategy, Transport
14
+ ├── external/ # External type definitions (Kafka, Redis, RMQ)
15
+ ├── inteceptor/ # CacheInterceptor, CacheInvalidateInterceptor
16
+ ├── interface/ # Type definitions
17
+ ├── module/ # CacheModule, providers
18
+ ├── provider/ # Cacheable provider factory
19
+ ├── service/ # CacheManager, CacheProvider, invalidation managers
20
+ └── utils/ # Key resolution, deprecation, validation
21
+ ```
22
+
23
+ ## Cache Strategies
24
+
25
+ | Strategy | L1 (Memory) | L2 (Redis) | Use Case |
26
+ |----------|-------------|------------|----------|
27
+ | `LEGACY` | Via cache-manager | Via cache-manager | Existing apps |
28
+ | `MEMORY` | ✅ LRU | ❌ | Single instance, dev |
29
+ | `DISTRIBUTED` | ❌ | ✅ | Multi-instance, shared |
30
+ | `MULTI_TIER` | ✅ LRU | ✅ | Optimal performance |
31
+
32
+ ## Critical: Legacy Mode Preservation
33
+
34
+ **DO NOT break backward compatibility.**
35
+
36
+ 1. Default behavior MUST remain `strategy: LEGACY`
37
+ 2. All existing APIs MUST continue to work
38
+ 3. Use `isEnhancedMode()` to guard enhanced-only features
39
+ 4. Deprecate gracefully (warn, don't fail)
40
+
41
+ ## Key Files
42
+
43
+ | File | Purpose |
44
+ |------|---------|
45
+ | `cache-manager.ts` | Main service, strategy switching |
46
+ | `cache-provider.ts` | Legacy cache-manager wrapper |
47
+ | `cacheable.provider.ts` | Enhanced mode factory |
48
+ | `redis-cache-invalidate.manager.ts` | Cross-instance invalidation |
49
+ | `redis-pattern-invalidation.ts` | SCAN-based bulk deletion |
50
+
51
+ ## Common Patterns
52
+
53
+ ### Adding New Features
54
+
55
+ ```typescript
56
+ // Guard enhanced-only features
57
+ async newFeature(): Promise<Result> {
58
+ if (this.useCacheable && this.cacheable) {
59
+ // Enhanced mode implementation
60
+ return this.enhancedImplementation();
61
+ }
62
+
63
+ // Legacy fallback or warning
64
+ this.logger.warn('Feature X is only available in enhanced mode');
65
+ return this.legacyFallback();
66
+ }
67
+ ```
68
+
69
+ ### Cache Key Resolution
70
+
71
+ ```typescript
72
+ import { resolveCacheKey } from '../utils';
73
+
74
+ // Always resolve keys consistently
75
+ const key = resolveCacheKey(['user', id]); // Returns: "USER:123"
76
+ ```
77
+
78
+ ### TTL Shorthand
79
+
80
+ ```typescript
81
+ import { parseTtl } from '../provider/cacheable.provider';
82
+
83
+ parseTtl('5m'); // 300000 (5 minutes)
84
+ parseTtl('1h'); // 3600000 (1 hour)
85
+ parseTtl('1d'); // 86400000 (1 day)
86
+ parseTtl(5000); // 5000 (passthrough)
87
+ ```
88
+
89
+ ## Testing
90
+
91
+ ```bash
92
+ # Run tests
93
+ npm test
94
+
95
+ # Run with coverage
96
+ npm run test:cov
97
+
98
+ # Watch mode
99
+ npm run test:watch
100
+ ```
101
+
102
+ ### Test File Conventions
103
+
104
+ ```
105
+ test/
106
+ ├── module/ # Module integration tests
107
+ ├── service/ # Service unit tests
108
+ ├── util/ # Utility tests
109
+ └── cacheable-*.spec.ts # Enhanced mode tests
110
+ ```
111
+
112
+ ## Safety Checklist
113
+
114
+ Before committing changes:
115
+
116
+ - [ ] All existing tests pass
117
+ - [ ] Legacy mode behavior unchanged
118
+ - [ ] New features have tests
119
+ - [ ] Memory leaks addressed (Maps cleared, listeners removed)
120
+ - [ ] Passwords/secrets not logged
121
+ - [ ] Error messages don't expose sensitive data
122
+
123
+ ## Known Issues
124
+
125
+ 1. **Jest Coverage**: Config points to `src/**` but code is in `lib/**`
126
+ 2. **Memory Leak**: `warnedFeatures` Set has no size limit
127
+ 3. **Memory Leak**: `RedisPatternInvalidation` created per call
128
+ 4. **Security**: Cache keys not sanitized
129
+
130
+ See `docs/CODE_REVIEW.md` and `docs/IMPLEMENTATION_PLAN.md` for details.
131
+
132
+ ## Dependencies
133
+
134
+ ### Required
135
+
136
+ - `@nestjs/common`, `@nestjs/core` (^8-11)
137
+ - `@nestjs/cache-manager` (^3.0.0) - Legacy mode
138
+ - `cache-manager` (>=6) - Legacy mode
139
+
140
+ ### Optional (Enhanced Mode)
141
+
142
+ - `cacheable` (^1.0.0)
143
+ - `@keyv/redis` (^3.0.0)
144
+ - `@qified/redis` (^1.0.0)
145
+ - `ioredis` - For invalidation broker
146
+
147
+ ## Migration
148
+
149
+ See `MIGRATION.md` for step-by-step guide from legacy to enhanced mode.