Title: Add IDistributedCache-based query caching behavior
Labels: enhancement, mediator
Body:
Problem
CachingQueryBehavior<TQuery, TResult> only supports IMemoryCache. In distributed systems (microservices, multi-instance deployments, Cortex.Streams scenarios), query results often need to be cached in Redis, SQL Server, or another distributed cache.
Proposed Solution
Create a Cortex.Mediator.Behaviors.DistributedCaching package (or add to core) with:
DistributedCachingQueryBehavior<TQuery, TResult> using IDistributedCache
ICacheSerializer interface for pluggable serialization (default: System.Text.Json)
- Support for the existing
ICacheableQuery and [Cacheable] attribute opt-in mechanisms
DistributedCachingOptions for default TTL, serialization settings, key prefix
services.AddMediatorDistributedCaching(options =>
{
options.DefaultAbsoluteExpiration = TimeSpan.FromMinutes(10);
options.Serializer = new JsonCacheSerializer();
});
Relationship to Existing Caching
This complements (not replaces) the existing IMemoryCache-based behavior. Users may use both (L1 in-memory + L2 distributed) via pipeline behavior ordering.
Title: Add
IDistributedCache-based query caching behaviorLabels:
enhancement,mediatorBody:
Problem
CachingQueryBehavior<TQuery, TResult>only supportsIMemoryCache. In distributed systems (microservices, multi-instance deployments, Cortex.Streams scenarios), query results often need to be cached in Redis, SQL Server, or another distributed cache.Proposed Solution
Create a
Cortex.Mediator.Behaviors.DistributedCachingpackage (or add to core) with:DistributedCachingQueryBehavior<TQuery, TResult>usingIDistributedCacheICacheSerializerinterface for pluggable serialization (default:System.Text.Json)ICacheableQueryand[Cacheable]attribute opt-in mechanismsDistributedCachingOptionsfor default TTL, serialization settings, key prefixRelationship to Existing Caching
This complements (not replaces) the existing
IMemoryCache-based behavior. Users may use both (L1 in-memory + L2 distributed) via pipeline behavior ordering.