24 lines
838 B
C#
24 lines
838 B
C#
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
namespace ApplianceRepair.Components.Pages
|
|
{
|
|
public partial class Home(IMemoryCache cache, HomePageReader homePageReader, ContentCardReader contentCardReader)
|
|
{
|
|
private HomePageModel? Model;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
if (!cache.TryGetValue(nameof(HomePageModel), out Model))
|
|
{
|
|
Model = await homePageReader.ReadLatestRecordWithModel(contentCardReader) ?? Defaults.DefaultHomePageContent;
|
|
|
|
var cacheOptions = new MemoryCacheEntryOptions()
|
|
.SetAbsoluteExpiration(TimeSpan.FromHours(24))
|
|
.SetSlidingExpiration(TimeSpan.FromHours(2));
|
|
|
|
cache.Set(nameof(HomePageModel), Model, cacheOptions);
|
|
}
|
|
}
|
|
}
|
|
}
|