title: How can I cache objects and read from memory if it exists instead of database?
body: <p>I have four classes as following:</p>
  
  <pre><code>public class Section
  {
      public int SectionId { get; set; }
      public string Name { get; set; }
      public string Title { get; set; }
      public string MetaTag { get; set; }
      public string MetaDescription { get; set; }
      public string UrlSafe { get; set; }
      public string Header { get; set; }
      public string ImageName { get; set; }
  }       
  
  public interface ISectionRepository
  {
      List&lt;Section&gt; GetAllSections();
  }
  
  public class SectionRepository : ISectionRepository
  {
      Context context = new Context();
  
      public List&lt;Section&gt; GetAllSections()
      {
          return context.Sections.ToList();
      }
  }
  
  public class SectionApplication
  {
      SectionRepository sectionRepo = new SectionRepository();
  
      public List&lt;Section&gt; GetAllSections()
      {
          return sectionRepo.GetAllSections();
      }
  }
  </code></pre>
  
  <p>And in my controller, I have</p>
  
  <pre><code>public class SectionController : Controller
  {
      SectionApplication sectionApp = new SectionApplication();
  
      public ActionResult Index()
      {
          return View(sectionApp.GetAllSections());
      }
  }
  </code></pre>
  
  <p>Now, I want to do cache sections on memory for a specific time in order to read sections from cache if it exists, else read it from database.</p>