Skip to content

[Feature]: Distributed Cache Support for Query Caching #218

@eneshoxha

Description

@eneshoxha

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestfeatureThis label is in use for minor version increments

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions