Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Jan 25, 2025
2 parents be2b8a3 + 816d30b commit da684f8
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
47 changes: 47 additions & 0 deletions src/Shiny.Mediator.DapperRequests/Contracts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace Shiny.Mediator;


public record DapperRequest<TResult>(
FormattableString Sql,
int? CommandTimeout = null,
string? RequestKey = null
) : IRequest<TResult>, IRequestKey
{
public string GetKey()
{
if (this.RequestKey != null)
return this.RequestKey;

var key = typeof(TResult).FullName + "_" + Sql;
return key;
}
}
public record DapperQuery<TResult>(
FormattableString Sql,
int? CommandTimeout = null,
string? RequestKey = null
) : DapperRequest<IEnumerable<TResult>>(
Sql,
CommandTimeout,
RequestKey
);

public record DapperFirstQuery<TResult>(
FormattableString Sql,
int? CommandTimeout = null,
string? RequestKey = null
) : DapperRequest<TResult>(
Sql,
CommandTimeout,
RequestKey
);

public record DapperScalar(
FormattableString Sql,
int? CommandTimeout = null,
string? RequestKey = null
) : DapperRequest<object>(
Sql,
CommandTimeout,
RequestKey
);
5 changes: 0 additions & 5 deletions src/Shiny.Mediator.DapperRequests/IDapperQuery.cs

This file was deleted.

5 changes: 5 additions & 0 deletions src/Shiny.Mediator/Caching/CacheExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TCache>(this ShinyConfigurator cfg) where TCache : class, ICacheService
{
cfg.Services.AddSingletonAsImplementedInterfaces<TCache>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down

0 comments on commit da684f8

Please sign in to comment.