Skip to content

Instantly share code, notes, and snippets.

Last active December 5, 2016 16:07
What would you like to do?
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()
return View(albums);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment