Last active
December 5, 2016 16:07
-
-
Save dcomartin/f6866a1a1d07e10195d69801fa9499ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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