Caching — Overview
The UDIOT caching system provides transparent, multi-layer caching with pluggable backends, tag-based invalidation, and an AI-powered analyzer that suggests optimal TTL values from observed access patterns.
Key Concepts
Transparent caching. The @AICache decorator wraps any async method so callers see no difference between a cache hit and a freshly computed value.
Multiple strategies. CacheStrategy controls which backend stores the entry: 'memory' (in-process LRU), 'redis', 'cdn', 'tiered', or 'auto'. The 'auto' value defers selection to the AICacheAnalyzer.
Three integration layers.
| Layer | API surface | Use case |
|---|---|---|
| Decorator | @AICache + @CacheInvalidate + @CacheKey |
Method-level caching in service classes |
| Manager | CacheManager.getOrSet() |
Explicit programmatic caching |
| Middleware | cacheMiddleware() |
HTTP response caching in a middleware pipeline |
AI-powered TTL selection. When ttl: 'auto' is passed, the manager scales the TTL relative to the factory's compute duration. The standalone AICacheAnalyzer tracks access patterns and can produce optimization reports and pre-warming predictions.
Tag-based invalidation. Every cached entry can carry string tags. Calling invalidate({ tags: ['user'] }) removes every entry tagged 'user' across all registered providers.
Event-driven invalidation. CacheManager.setupEventInvalidation() maps domain event names to keys, tags, or patterns to remove when handleEvent() is called.
How the Layers Fit Together
Domain event / method call
│
▼
@CacheInvalidate ──► CacheManager.invalidate()
│
@AICache ──► CacheManager.getOrSet()
│
cacheMiddleware ──► CacheManager.get() / set()
│
ICacheProvider (memory / redis / ...)
See Also
- cache-manager.md —
CacheManagerAPI reference - providers.md —
ICacheProviderinterface and built-in providers - decorators.md —
@AICache,@CacheInvalidate,@CacheKey - invalidation.md —
TagRegistry,PatternMatcher,CacheInvalidator - middleware.md — HTTP response caching middleware