feat: Distributed cache interceptor for queries (ICacheableQuery<TResponse>)#152
feat: Distributed cache interceptor for queries (ICacheableQuery<TResponse>)#152
ICacheableQuery<TResponse>)#152Conversation
ICacheableQuery<TResponse>)
6c64782 to
bd52217
Compare
|
@copilot Please update the README files for each project and the solution readme |
Done in commit
The provider packages (Polly, EntityFramework, SqlServer, Dapr) were left unchanged as query caching is unrelated to their functionality. |
src/NetEvolve.Pulse/Interceptors/DistributedCacheQueryInterceptor.cs
Outdated
Show resolved
Hide resolved
src/NetEvolve.Pulse/Interceptors/DistributedCacheQueryInterceptor.cs
Outdated
Show resolved
Hide resolved
src/NetEvolve.Pulse/Interceptors/DistributedCacheQueryInterceptor.cs
Outdated
Show resolved
Hide resolved
|
@copilot Please solve open comments |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #152 +/- ##
==========================================
+ Coverage 86.12% 86.48% +0.36%
==========================================
Files 42 44 +2
Lines 1312 1347 +35
Branches 123 130 +7
==========================================
+ Hits 1130 1165 +35
Misses 145 145
Partials 37 37 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Addressed in commit
|
Agent-Logs-Url: https://github.com/dailydevops/pulse/sessions/0b247b98-039d-4a9e-b2a7-18484442a5be Co-authored-by: samtrion <3283596+samtrion@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dailydevops/pulse/sessions/255ad709-91b7-4e0e-930f-5e1f07cdb5dd Co-authored-by: samtrion <3283596+samtrion@users.noreply.github.com>
… and CacheExpirationMode Agent-Logs-Url: https://github.com/dailydevops/pulse/sessions/a0916941-2359-4365-aa27-e7bb363858dc Co-authored-by: samtrion <3283596+samtrion@users.noreply.github.com>
6f7e513 to
ed9f327
Compare
Extract logic for setting DistributedCacheEntryOptions into a new private GetCacheEntryOptions method. This improves readability and maintainability by centralizing expiration mode handling and reducing code duplication.
Agent-Logs-Url: https://github.com/dailydevops/pulse/sessions/9b1d5eb8-2b05-4a74-b9b4-04fedcf21561 Co-authored-by: samtrion <3283596+samtrion@users.noreply.github.com>
| return this; | ||
| } | ||
|
|
||
| /// <inheritdoc /> |
There was a problem hiding this comment.
Implemented IMediatorConfigurator.AddQueryCaching(Action?) — adding this required interface method breaks existing implementers. Add a default interface implementation or keep the interface unchanged.
Details
✨ AI Reasoning
The concrete MediatorConfigurator type now includes a new public AddQueryCaching method to match the updated interface. While adding the implementation itself is fine, the underlying interface addition forces all external implementers of IMediatorConfigurator to add the same method, breaking source compatibility.
🔧 How do I fix it?
Support both old and new parameter names during transition periods. Add new optional parameters with defaults. Keep existing response fields while adding new ones. Focus on backwards compatibility.
Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
Adds transparent
IDistributedCachecaching for queries via a pipeline interceptor, eliminating per-handler cache boilerplate. Caching is opt-in per query type viaICacheableQuery<TResponse>.New contracts (
NetEvolve.Pulse.Extensibility)ICacheableQuery<TResponse>— extendsIQuery<TResponse>withCacheKeyandExpiryproperties.CacheExpirationMode— enum to distinguish betweenAbsolute(default) andSlidingexpiration.QueryCachingOptions— options class with:JsonSerializerOptions— for custom cache serialization (defaults toJsonSerializerOptions.Default)ExpirationMode— absolute vs. sliding expiry (defaults toAbsolute)DefaultExpiry— fallbackTimeSpan?applied whenICacheableQuery<TResponse>.Expiryreturnsnull(defaults tonull, meaning no explicit expiration)New interceptor (
NetEvolve.Pulse)DistributedCacheQueryInterceptor<TQuery, TResponse>— registered asIRequestInterceptor<,>(scoped). Behavior:ICacheableQueryqueries pass through unchanged.System.Text.Json, stores with optional expiry.IDistributedCachenot registered → falls through silently.JsonSerializerOptionsfromQueryCachingOptions.ICacheableQuery<TResponse>.Expiry ?? QueryCachingOptions.DefaultExpiry; applied as absolute or sliding based onExpirationMode.Registration
AddQueryCaching(Action<QueryCachingOptions>? configure = null)added toIMediatorConfiguratorand implemented inMediatorConfigurator. Options are registered via the standard Options pattern.Test coverage
JsonSerializerOptions,DefaultExpiryapplied when query expiry isnull, query expiry overridesDefaultExpiry.MemoryDistributedCacheverifying second-invocation cache hit, non-cacheable query bypass, no-cache fallthrough, sliding expiration, custom JSON options, andDefaultExpiryfallback.Breaking change (interface)
Existing
IMediatorConfiguratorstub implementations in tests (Polly, SqlServer, EntityFramework) updated to satisfy the updatedAddQueryCaching(Action<QueryCachingOptions>? configure = null)signature.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.