Compare commits
3 Commits
af492dedff
...
db05b0b815
| Author | SHA1 | Date | |
|---|---|---|---|
| db05b0b815 | |||
| 16ee1f98ed | |||
| fec33bff1d |
@@ -15,24 +15,31 @@ namespace AS1024.GeoFeed.Controllers
|
|||||||
{
|
{
|
||||||
private readonly IGeoFeedProvider builder;
|
private readonly IGeoFeedProvider builder;
|
||||||
private readonly IMemoryCache memoryCache;
|
private readonly IMemoryCache memoryCache;
|
||||||
|
private readonly IWebHostEnvironment environment;
|
||||||
private const string GeoFeedCacheKey = "GeoFeedData";
|
private const string GeoFeedCacheKey = "GeoFeedData";
|
||||||
|
|
||||||
public GeofeedController(IGeoFeedProvider builder,
|
public GeofeedController(IGeoFeedProvider builder,
|
||||||
IMemoryCache memoryCache) {
|
IMemoryCache memoryCache,
|
||||||
|
IWebHostEnvironment environment) {
|
||||||
this.builder = builder;
|
this.builder = builder;
|
||||||
this.memoryCache = memoryCache;
|
this.memoryCache = memoryCache;
|
||||||
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("")]
|
[Route("")]
|
||||||
public async Task<IActionResult> Get()
|
public async Task<IActionResult> Get()
|
||||||
{
|
{
|
||||||
if (!memoryCache.TryGetValue(GeoFeedCacheKey, out List<IPGeoFeed>? feed))
|
if (!memoryCache.TryGetValue(GeoFeedCacheKey, out List<IPGeoFeed>? feed)
|
||||||
|
&& environment.IsProduction())
|
||||||
{
|
{
|
||||||
feed = await builder.GetGeoFeedData();
|
feed = await builder.GetGeoFeedData();
|
||||||
var cacheEntryOptions = new MemoryCacheEntryOptions()
|
var cacheEntryOptions = new MemoryCacheEntryOptions()
|
||||||
.SetSlidingExpiration(TimeSpan.FromMinutes(15));
|
.SetSlidingExpiration(TimeSpan.FromMinutes(15));
|
||||||
memoryCache.Set(GeoFeedCacheKey, feed, cacheEntryOptions);
|
memoryCache.Set(GeoFeedCacheKey, feed, cacheEntryOptions);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
feed = await builder.GetGeoFeedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
var csvContent = feed.ToGeoFeedCsv(); // Assuming ToGeoFeedCsv() returns a string in CSV format.
|
var csvContent = feed.ToGeoFeedCsv(); // Assuming ToGeoFeedCsv() returns a string in CSV format.
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ namespace AS1024.GeoFeed.GeoFeedBuilder
|
|||||||
GeolocCity = data.CustomFields.GeolocCity,
|
GeolocCity = data.CustomFields.GeolocCity,
|
||||||
GeolocRegion = data.CustomFields.GeolocRegion,
|
GeolocRegion = data.CustomFields.GeolocRegion,
|
||||||
GeolocCountry = data.CustomFields.GeolocCountry,
|
GeolocCountry = data.CustomFields.GeolocCountry,
|
||||||
GeolocHasLocation = data.CustomFields.GeolocHasLocation
|
GeolocHasLocation = data.CustomFields.GeolocHasLocation,
|
||||||
|
GeolocPostalCode = data.CustomFields.GeolocPostalCode
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ namespace AS1024.GeoFeed.Models
|
|||||||
public bool? GeolocHasLocation { get; set; }
|
public bool? GeolocHasLocation { get; set; }
|
||||||
[JsonProperty("geoloc_region")]
|
[JsonProperty("geoloc_region")]
|
||||||
public string? GeolocRegion { get; set; }
|
public string? GeolocRegion { get; set; }
|
||||||
|
[JsonProperty("geoloc_postal_code")]
|
||||||
|
public string? GeolocPostalCode { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user