diff --git a/MPM-Betting.Aspire/MPM-Betting.Aspire.AppHost/Program.cs b/MPM-Betting.Aspire/MPM-Betting.Aspire.AppHost/Program.cs index 985b634..75702ff 100644 --- a/MPM-Betting.Aspire/MPM-Betting.Aspire.AppHost/Program.cs +++ b/MPM-Betting.Aspire/MPM-Betting.Aspire.AppHost/Program.cs @@ -38,14 +38,29 @@ .WithDataVolume() .AddDatabase("MPM-Betting"); -var api = builder.AddProject("api") - .WithReference(sql) - .WithReference(redis); - -var blazor = builder.AddProject("blazor") - .WithReference(api) - .WithReference(redis) - .WithReference(sql); +if (builder.ExecutionContext.IsPublishMode) +{ + var api = builder.AddProject("api") + .WithReference(sql) + .WithReference(redis); + + var blazor = builder.AddProject("blazor") + .WithReference(api) + .WithReference(redis) + .WithReference(sql); +} +else +{ + var api = builder.AddProjectWithDotnetWatch("api") + .WithReference(sql) + .WithReference(redis); + + var blazor = builder.AddProjectWithDotnetWatch("blazor") + .WithEnvironment("services__api__http__0", "http://localhost:5241") + .WithReference(redis) + .WithReference(sql); +} + builder.Build().Run(); diff --git a/MPM-Betting.Services/Data/FootballApi.cs b/MPM-Betting.Services/Data/FootballApi.cs index 22e802a..36c41f1 100644 --- a/MPM-Betting.Services/Data/FootballApi.cs +++ b/MPM-Betting.Services/Data/FootballApi.cs @@ -38,7 +38,7 @@ public static WebApplication MapFootballEndpoints(this WebApplication app) private static async Task 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}"; diff --git a/MPM-Betting.Services/Data/Utils.cs b/MPM-Betting.Services/Data/Utils.cs index 792cc59..33ceb65 100644 --- a/MPM-Betting.Services/Data/Utils.cs +++ b/MPM-Betting.Services/Data/Utils.cs @@ -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(IDistributedCache cache, TimeSpan expiration, string cacheKey, Func generator) { var cachedValueBytes = cache.Get(cacheKey); @@ -22,7 +24,7 @@ public static T GetViaCache(IDistributedCache cache, TimeSpan expiration, str public static async Task GetViaCache(IDistributedCache cache, TimeSpan expiration, string cacheKey, Func> generator) { - var cachedValueBytes = cache.Get(cacheKey); + var cachedValueBytes = await cache.GetAsync(cacheKey); if (cachedValueBytes != null) { return JsonSerializer.Deserialize(cachedValueBytes) ?? throw new InvalidOperationException(); @@ -30,7 +32,7 @@ public static async Task GetViaCache(IDistributedCache cache, TimeSpan exp 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; }