diff --git a/src/Shiny.Mediator.DapperRequests/Contracts.cs b/src/Shiny.Mediator.DapperRequests/Contracts.cs new file mode 100644 index 0000000..e5e6454 --- /dev/null +++ b/src/Shiny.Mediator.DapperRequests/Contracts.cs @@ -0,0 +1,47 @@ +namespace Shiny.Mediator; + + +public record DapperRequest( + FormattableString Sql, + int? CommandTimeout = null, + string? RequestKey = null +) : IRequest, IRequestKey +{ + public string GetKey() + { + if (this.RequestKey != null) + return this.RequestKey; + + var key = typeof(TResult).FullName + "_" + Sql; + return key; + } +} +public record DapperQuery( + FormattableString Sql, + int? CommandTimeout = null, + string? RequestKey = null +) : DapperRequest>( + Sql, + CommandTimeout, + RequestKey +); + +public record DapperFirstQuery( + FormattableString Sql, + int? CommandTimeout = null, + string? RequestKey = null +) : DapperRequest( + Sql, + CommandTimeout, + RequestKey +); + +public record DapperScalar( + FormattableString Sql, + int? CommandTimeout = null, + string? RequestKey = null +) : DapperRequest( + Sql, + CommandTimeout, + RequestKey +); diff --git a/src/Shiny.Mediator.DapperRequests/IDapperQuery.cs b/src/Shiny.Mediator.DapperRequests/IDapperQuery.cs deleted file mode 100644 index f104116..0000000 --- a/src/Shiny.Mediator.DapperRequests/IDapperQuery.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Shiny.Mediator; - -public record DapperQuery(FormattableString Sql, int? CommandTimeout = null) : IRequest>; -public record DapperFirstQuery(FormattableString Sql, int? CommandTimeout = null) : IRequest; -public record DapperScalar(FormattableString Sql, int? CommandTimeout = null) : IRequest; diff --git a/src/Shiny.Mediator/Caching/CacheExtensions.cs b/src/Shiny.Mediator/Caching/CacheExtensions.cs index b720640..00df509 100644 --- a/src/Shiny.Mediator/Caching/CacheExtensions.cs +++ b/src/Shiny.Mediator/Caching/CacheExtensions.cs @@ -7,6 +7,11 @@ namespace Shiny.Mediator; public static class CacheExtensions { + public static readonly (string Key, bool Value) ForceCacheRefreshHeader = ("ForceCacheRefresh", true); + + public static bool HasForceCacheRefresh(this RequestContext context) + => context.Values.ContainsKey(ForceCacheRefreshHeader.Key); + public static ShinyConfigurator AddCaching(this ShinyConfigurator cfg) where TCache : class, ICacheService { cfg.Services.AddSingletonAsImplementedInterfaces(); diff --git a/src/Shiny.Mediator/Caching/Infrastructure/CachingRequestMiddleware.cs b/src/Shiny.Mediator/Caching/Infrastructure/CachingRequestMiddleware.cs index 56f9287..9c1c2ef 100644 --- a/src/Shiny.Mediator/Caching/Infrastructure/CachingRequestMiddleware.cs +++ b/src/Shiny.Mediator/Caching/Infrastructure/CachingRequestMiddleware.cs @@ -42,7 +42,7 @@ CancellationToken cancellationToken return await next().ConfigureAwait(false); TResult result = default!; - if (context.Request is ICacheControl { ForceRefresh: true }) + if (context.Request is ICacheControl { ForceRefresh: true } || context.HasForceCacheRefresh()) { logger.LogDebug("Cache Forced Refresh - {Request}", context.Request); result = await next().ConfigureAwait(false); diff --git a/version.json b/version.json index 5d07a9c..379d6f2 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "3.0.0-beta.{height}", + "version": "3.1.0-beta.{height}", "assemblyVersion": { "precision": "revision" },