Rename file
This commit is contained in:
36
AS1024.GeoFeed/GeoFeedBuilder/PreloadGeoFeed.cs
Normal file
36
AS1024.GeoFeed/GeoFeedBuilder/PreloadGeoFeed.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
using AS1024.GeoFeed.Interfaces;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace AS1024.GeoFeed.GeoFeedBuilder
|
||||
{
|
||||
public class PreLoadGeoFeed : IHostedService
|
||||
{
|
||||
private readonly ILogger<PreLoadGeoFeed> logger;
|
||||
private readonly IGeoFeedProvider provider;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
private const string GeoFeedCacheKey = "GeoFeedData";
|
||||
|
||||
public PreLoadGeoFeed(ILogger<PreLoadGeoFeed> logger,
|
||||
IGeoFeedProvider provider,
|
||||
IMemoryCache memoryCache)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.provider = provider;
|
||||
this.memoryCache = memoryCache;
|
||||
}
|
||||
|
||||
async Task IHostedService.StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
logger.LogInformation("Preloading GeoFeed data in memory...");
|
||||
var feed = await provider.GetGeoFeedData();
|
||||
var cacheEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(45));
|
||||
memoryCache.Set(GeoFeedCacheKey, feed, cacheEntryOptions);
|
||||
}
|
||||
|
||||
Task IHostedService.StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user