You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A module to provide caching capabilities (in-memory, Redis, etc.) for NexusDI, built on top of cache-manager. This approach leverages cache-manager’s robust, tiered caching and multi-backend support, while exposing a DI-friendly API and decorator-based caching for services.
Motivation
Easy DI for cache clients: Make it simple to inject and mock cache clients in services.
Declarative caching: Use decorators for method-level caching, reducing boilerplate.
Support for multiple backends: Instantly support memory, Redis, Memcached, Mongo, and more via Keyv adapters.
Tiered/multi-store caching: Let cache-manager handle store selection, TTLs, and fallbacks.
Extensibility: Enable custom cache strategies and advanced features by passing options directly to cache-manager.
Proposed Features
Use cache-manager as the underlying cache abstraction.
Register cache backends and tiered caches via config (e.g., in container.json).
Inject cache clients/services into providers using @InjectCache().
Support for multiple named caches (e.g., default, session, etc.).
@Cacheable() decorator for methods to cache results.
Support for TTL, cache invalidation, and custom cache keys.
Pass all options/config down to cache-manager for full feature access.
import{InjectCache,Cacheable}from'@nexusdi/cache';classProductService{constructor(@InjectCache()privatecache: Cache){}
@Cacheable({ttl: 120})asyncgetProduct(id: string){// fetch product from DB or API}}classSessionService{constructor(@InjectCache('session')privatesessionCache: Cache){}asyncgetSession(sessionId: string){returnthis.sessionCache.get(sessionId);}}
Store Selection and Tiered Caching
When you configure multiple stores for a cache, cache-manager treats them as a tiered cache (e.g., memory first, Redis as fallback).
You interact with the cache as a whole; cache-manager handles which store to use for reads/writes and manages TTLs.
If you need multiple independent caches (e.g., for different data domains), configure and inject named caches (e.g., default, session).
Open Questions
Which cache-manager features should be surfaced in the DI API?
Any backends or adapters you want prioritized for first-class support?
Any pain points with cache-manager you’d like to see improved in a DI context?
Should we provide additional decorators for cache invalidation or busting?
How to best support mocking/overriding cache for testing?
API Sketch
import{InjectCache,Cacheable}from'@nexusdi/cache';classProductService{constructor(@InjectCache()privatecache: Cache){}
@Cacheable({ttl: 120})asyncgetProduct(id: string){// fetch product from DB or API}}classSessionService{constructor(@InjectCache('session')privatesessionCache: Cache){}asyncgetSession(sessionId: string){returnthis.sessionCache.get(sessionId);}}
Call for Feedback
What cache backends do you use or want supported?
What features or decorators would you want for caching?
Any pain points with caching in DI frameworks or with cache-manager?
How important is support for cache invalidation, custom keys, or advanced features?
Any other features or decorator options you’d want?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
A module to provide caching capabilities (in-memory, Redis, etc.) for NexusDI, built on top of
cache-manager. This approach leverages cache-manager’s robust, tiered caching and multi-backend support, while exposing a DI-friendly API and decorator-based caching for services.Motivation
Proposed Features
cache-manageras the underlying cache abstraction.container.json).@InjectCache().default,session, etc.).@Cacheable()decorator for methods to cache results.Example Workflow
Configure the cache module in
container.json:{ "cache": { "default": { "stores": [ { "backend": "memory", "ttl": 60 }, { "backend": "redis", "url": "redis://localhost:6379", "ttl": 300 } ] }, "session": { "stores": [ { "backend": "redis", "url": "redis://localhost:6379", "ttl": 3600 } ] } } }Register the cache module:
Inject cache clients and use decorators:
Store Selection and Tiered Caching
default,session).Open Questions
API Sketch
Call for Feedback
Beta Was this translation helpful? Give feedback.
All reactions