title: HttpContext and Caching in .NET Core >= 1.0
body: <p>I am trying to port some libraries from the old MVC5 System.Web based stack to .Net Core. One issue I am having is the changes in the caching. For example, in MVC5 I was able to read and write i18n related data:</p>
  
  <p>[Code Snippet 1]</p>
  
  <pre><code>public static Dictionary&lt;string, IEnumerable&lt;CoreDictionaryResource&gt;&gt; DictionaryResourcesCache {
      get { return (Dictionary&lt;string, IEnumerable&lt;CoreDictionaryResource&gt;&gt;)HttpContext.Current.Cache(string.Concat(_Dictionary, DictionaryID, CultureID)); }
      set { HttpContext.Current.Cache(string.Concat(_Dictionary, DictionaryID, CultureID)) = value; }
  }
  </code></pre>
  
  <p>However, I am reliably informed that <code>System.Web</code> and its <code>HttpContext</code> does not contain a Cache field. I can see a <code>Current</code> field and then a whole host of fields within this such as <code>Application</code> and <code>Session</code> but alas no <code>Cache</code>. </p>
  
  <p>I've done the necessary in <code>Startup.cs</code> and the app is configured to use both in memory caching and sessions. I know that the sessions work as I have other POCOs cached using </p>
  
  <p>[Code Snippet 2]</p>
  
  <pre><code> return System.Web.HttpContext.Current.Session.GetObject&lt;User&gt;("AuthenticatedUser");
  </code></pre>
  
  <p>where <code>GetObject</code> in an extension I created. </p>
  
  <p>Am I barking up the wrong tree trying to use <code>HttpContext</code> to read out from the Cache or perhaps I need to use <code>IDistributedCache</code> as see <a href="https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed" rel="noreferrer">here,</a> <a href="https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory" rel="noreferrer">here</a> and on <a href="https://stackoverflow.com/questions/28269072/how-to-cache-resources-in-asp-net-core">SO</a>.</p>
  
  <p>But really I just to port the method within [Code Snippet 1]... </p>
  
  <p>Any pointer you can give on the new .Net Core with regards to caching would be really helpful. </p>
  
  <p>Just FYI I do not want any logic in Controllers, nor in Views. The application I am building usings separate DLLs for data access and logic so please don't post any examples with DI into the Controllers. This issue is more at an infrastrcture level before it hits the MVC stack. </p>
  
  <p>Thanks guys and gals.</p>