title: Update cache upon modified entity
body: <p>I am using IMemoryCache and running an asp-net core project. On the home page I have listed some movies, which are cached for like 10 minutes. Is there a way to update the cache, If a movie has been created/deleted/edit, If if those 10 minutes have not passed?</p>
  
  <pre><code>using Microsoft.AspNetCore.Mvc;
  using Microsoft.Extensions.Caching.Memory;
  using MovieManagement.Models;
  using MovieManagement.Models.Home;
  using MovieManagement.Services.Contracts;
  using MovieManagement.ViewModels;
  using System;
  using System.Collections.Generic;
  using System.Diagnostics;
  using System.Threading.Tasks;
  
  namespace MovieManagement.Controllers
  {
      public class HomeController : Controller
      {
          private readonly IMovieService movieService;
          private readonly IMemoryCache cacheService;
  
          public HomeController(IMovieService movieService, IMemoryCache cache)
          {
              this.movieService = movieService ?? throw new ArgumentNullException(nameof(movieService));
              this.cacheService = cache ?? throw new ArgumentNullException(nameof(cache));
          }
  
          public async Task&lt;IActionResult&gt; Index()
          {
              var model = new HomeIndexViewModel();
  
  
              var cachedMovies = await this.cacheService.GetOrCreateAsync("Movies", async entry =&gt;
              {
                  entry.AbsoluteExpiration = DateTime.UtcNow.AddSeconds(20);
                  var movies = await this.movieService.GetTopRatedMovies();
                  return movies;
              });
  
              model.Movies = cachedMovies;
  
              return this.View(model);
          }
      }
  }
  </code></pre>