// GET: Joke public async Task <ActionResult> Index() { IEnumerable <Joke> jokes; // Look for cache key. if (!_cache.TryGetValue(CacheKeys.Jokes, out jokes)) { // Key not in cache, so get data. jokes = await _data.GetAll(); // Set cache options. var cacheEntryOptions = new MemoryCacheEntryOptions() // Keep in cache for this time, reset time if accessed. .SetSlidingExpiration(TimeSpan.FromMinutes(2)); // Save data in cache. _cache.Set(CacheKeys.Jokes, jokes, cacheEntryOptions); } return(View(jokes.OrderByDescending(j => j.Id).ToList())); }
public async Task <IEnumerable <Joke> > Get() { var jokes = await _data.GetAll(); return(jokes.ToList()); }
public async Task <IEnumerable <Joke> > Get() { var jokes = await _data.GetAll(); return(jokes.OrderByDescending(j => j.Id).ToList()); }