Summary
Provide a caching decorator so query results can be cached declaratively via an attribute like [CacheableQuery].
Context
From V5 discussion #273. Caching is one of the most common cross-cutting concerns for queries and is a natural fit for Darker's decorator pipeline.
Proposal
- Create a
[CacheableQuery] attribute with configurable expiry, cache key strategy, etc.
- Create a
CacheableQueryDecorator that checks the cache before invoking next, and populates the cache after
- Support Microsoft's
HybridCache (new in .NET 9) as the primary caching abstraction
- Consider also supporting
FusionCache as a popular alternative
- Cache key generation should be pluggable (default: serialize the query object)
- Support cache invalidation patterns (e.g. via
QueryContext.Bag)
- Package as
Paramore.Darker.Caching or similar
Design Considerations
- Queries are inherently cacheable (read-only, deterministic for the same input)
- The decorator pattern makes this clean: cache check in
Execute, populate on next return
- Cache key must account for all query properties that affect the result
Summary
Provide a caching decorator so query results can be cached declaratively via an attribute like
[CacheableQuery].Context
From V5 discussion #273. Caching is one of the most common cross-cutting concerns for queries and is a natural fit for Darker's decorator pipeline.
Proposal
[CacheableQuery]attribute with configurable expiry, cache key strategy, etc.CacheableQueryDecoratorthat checks the cache before invokingnext, and populates the cache afterHybridCache(new in .NET 9) as the primary caching abstractionFusionCacheas a popular alternativeQueryContext.Bag)Paramore.Darker.Cachingor similarDesign Considerations
Execute, populate onnextreturn