in UnicornStore/Areas/Admin/Controllers/StoreManagerController.cs [45:80]
public async Task<IActionResult> Details(
[FromServices] IMemoryCache cache,
int id)
{
var cacheKey = GetCacheKey(id);
Blessing blessing;
if (!cache.TryGetValue(cacheKey, out blessing))
{
blessing = await DbContext.Blessings
.Where(a => a.BlessingId == id)
.Include(a => a.Unicorn)
.Include(a => a.Genre)
.FirstOrDefaultAsync();
if (blessing != null)
{
if (_appSettings.CacheDbResults)
{
//Remove it from cache if not retrieved in last 10 minutes.
cache.Set(
cacheKey,
blessing,
new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromMinutes(10)));
}
}
}
if (blessing == null)
{
cache.Remove(cacheKey);
return NotFound();
}
return View(blessing);
}