Redis Cache Service
Purpose
Generate Redis cache service with tenant-prefixed keys to prevent cross-tenant data leakage, TTL management for memory efficiency, and cache invalidation patterns.
When to Use
- •Caching frequently accessed data
- •Session storage
- •Rate limiting
- •Reducing database load
- •Tenant-isolated caching
What It Generates
Directory Structure
code
apps/api/src/modules/{feature}/services/
├── {feature}-cache.service.ts
├── {feature}-cache.service.spec.ts
└── index.ts
Patterns Enforced
Tenant-Prefixed Keys
Cache keys use format: tenant:{tenantId}:{key}
- •Prevents cross-tenant cache pollution
- •Enables tenant-wide cache clearing
- •Isolates rate limit counters
TTL Management
- •All cache keys have TTL
- •Default TTL: 5 minutes (300 seconds)
- •Session TTL: 24 hours (86400 seconds)
- •No infinite TTL (prevents memory leaks)
Cache Invalidation
- •Pattern-based deletion:
delPattern('tenant:{tenantId}:*') - •Tag-based invalidation
- •Automatic invalidation on updates
Usage Example
bash
/skill cache-redis --name=User --methods='cacheUser,cachePermissions,clearUserCache'
Related Files
- •Data Repository - Repository using cache
- •BullMQ Queues - Queue jobs with caching