1.9.5.Data Cache

  • Use data cache

      public ViewResult Index()
          {
              if (MemoryCache.Default["Genre"] == null)
              {
                  MemoryCache.Default["Genre"] = _context.genreType.ToList();
              }
    
              var genres = MemoryCache.Default["Genre"] as IEnumerable<Genre>;
    
              return View();
          }
  • Poor advice in 2 reasons:

    • 1.By blindly storing data in the cache you will increase memory consumption of your application

    • 2.It will lead to all kinds of unnecessary complexities both at the architectural and code level especially when you're working with entity framework

Last updated