Append when the GeoFeed is retrieved and if it was generated from in memory cache

This commit is contained in:
2024-01-16 13:05:58 -08:00
parent 690a117ffd
commit c1ed05a335
3 changed files with 22 additions and 5 deletions

View File

@@ -36,10 +36,12 @@ namespace AS1024.GeoFeed.Controllers
[Route("")]
public async Task<IActionResult> Get()
{
bool isCached = true;
try
{
if (!memoryCache.TryGetValue(GeoFeedCacheKey, out List<IPGeoFeed>? feed))
{
isCached = false;
feed = await builder.GetGeoFeedData();
if (environment.IsProduction())
{
@@ -49,7 +51,7 @@ namespace AS1024.GeoFeed.Controllers
}
}
return ReturnFile(feed);
return ReturnFile(feed, isCached);
} catch (HttpRequestException ex)
{
logger.LogWarning($"Temporary failure of retrieving GeoData from upstream. {ex}");
@@ -66,9 +68,9 @@ namespace AS1024.GeoFeed.Controllers
}
[NonAction]
private IActionResult ReturnFile(List<IPGeoFeed>? feed)
private IActionResult ReturnFile(List<IPGeoFeed>? feed, bool isCached = false)
{
string csvContent = feed.ToGeoFeedCsv(); // Assuming ToGeoFeedCsv() returns a string in CSV format.
string csvContent = feed.ToGeoFeedCsv(true, isCached); // Assuming ToGeoFeedCsv() returns a string in CSV format.
return ReturnFile(csvContent);
}