Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Last active December 5, 2016 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/f6866a1a1d07e10195d69801fa9499ea to your computer and use it in GitHub Desktop.
Save dcomartin/f6866a1a1d07e10195d69801fa9499ea to your computer and use it in GitHub Desktop.
public async Task<IActionResult> Index([FromServices] MusicStoreContext dbContext, [FromServices] IMemoryCache cache)
{
var cacheKey = "topselling";
List<Album> albums;
if (!cache.TryGetValue(cacheKey, out albums))
{
albums = await GetTopSellingAlbumsAsync(dbContext, 6);
if (albums != null && albums.Count > 0)
{
if (_appSettings.CacheDbResults)
{
cache.Set(cacheKey, albums,
new MemoryCacheEntryOptions()
.SetAbsoluteExpiration(TimeSpan.FromMinutes(10))
.SetPriority(CacheItemPriority.High));
}
}
}
return View(albums);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment