Skip to content

Commit

Permalink
Enable HotReloading by default
Browse files Browse the repository at this point in the history
  • Loading branch information
g-martin772 committed Apr 15, 2024
1 parent af40b54 commit 59b9b84
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
31 changes: 23 additions & 8 deletions MPM-Betting.Aspire/MPM-Betting.Aspire.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,29 @@
.WithDataVolume()
.AddDatabase("MPM-Betting");

var api = builder.AddProject<MPM_Betting_Api>("api")
.WithReference(sql)
.WithReference(redis);

var blazor = builder.AddProject<MPM_Betting_Blazor>("blazor")
.WithReference(api)
.WithReference(redis)
.WithReference(sql);
if (builder.ExecutionContext.IsPublishMode)
{
var api = builder.AddProject<MPM_Betting_Api>("api")
.WithReference(sql)
.WithReference(redis);

var blazor = builder.AddProject<MPM_Betting_Blazor>("blazor")
.WithReference(api)
.WithReference(redis)
.WithReference(sql);
}
else
{
var api = builder.AddProjectWithDotnetWatch<MPM_Betting_Api>("api")
.WithReference(sql)
.WithReference(redis);

var blazor = builder.AddProjectWithDotnetWatch<MPM_Betting_Blazor>("blazor")
.WithEnvironment("services__api__http__0", "http://localhost:5241")
.WithReference(redis)
.WithReference(sql);
}


builder.Build().Run();

Expand Down
2 changes: 1 addition & 1 deletion MPM-Betting.Services/Data/FootballApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static WebApplication MapFootballEndpoints(this WebApplication app)

private static async Task<LeagueTable> GetLeagueTable(IDistributedCache cache, int leagueId, string? season)
{
return await Utils.GetViaCache(cache, TimeSpan.FromMinutes(1), $"leagueTable-{leagueId}-{season ?? "latest"}", async () =>
return await Utils.GetViaCache(cache, TimeSpan.FromSeconds(1), $"leagueTable-{leagueId}-{season ?? "latest"}", async () =>
{
var client = new HttpClient();
var url = $"https://www.fotmob.com/api/leagues?id={leagueId}";
Expand Down
6 changes: 4 additions & 2 deletions MPM-Betting.Services/Data/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace MPM_Betting.Services.Data;

public partial class Utils
{
// TODO: Implement utility method for getting cached JSON data via external endpoint

public static T GetViaCache<T>(IDistributedCache cache, TimeSpan expiration, string cacheKey, Func<T> generator)
{
var cachedValueBytes = cache.Get(cacheKey);
Expand All @@ -22,15 +24,15 @@ public static T GetViaCache<T>(IDistributedCache cache, TimeSpan expiration, str

public static async Task<T> GetViaCache<T>(IDistributedCache cache, TimeSpan expiration, string cacheKey, Func<Task<T>> generator)
{
var cachedValueBytes = cache.Get(cacheKey);
var cachedValueBytes = await cache.GetAsync(cacheKey);
if (cachedValueBytes != null)
{
return JsonSerializer.Deserialize<T>(cachedValueBytes) ?? throw new InvalidOperationException();
}

var value = await generator.Invoke();
var serializedValue = JsonSerializer.SerializeToUtf8Bytes(value);
cache.Set(cacheKey, serializedValue, new DistributedCacheEntryOptions { SlidingExpiration = expiration });
await cache.SetAsync(cacheKey, serializedValue, new DistributedCacheEntryOptions { SlidingExpiration = expiration });

return value;
}
Expand Down

0 comments on commit 59b9b84

Please sign in to comment.