title: Efficient caching of Identity related entities
body: <p>I'm using asp.net MVC5 and asp.net Identity v2 (from the nightly releases) but I think this question still applies to Identity V1.</p>
  
  <p>I have a membership system and i am linking a <code>AspNetUser</code> entity to my <code>membershipuser</code> entity via a field  <code>AspUserId</code> in the <code>membershipuser</code> table.</p>
  
  <pre class="lang-cs prettyprint-override"><code>public partial class membershipuser
  {
      public int id { get; set; }
      public string full_name { get; set; }
      public string address { get; set; }
      public string AspNetUserId { get; set; }
      .....
  }
  </code></pre>
  
  <p>I was wondering what is the best method of caching your membershipuser record for the life of the request. This way:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public static class extensions
      {
          public static membershipuser GetMember(this System.Security.Principal.IPrincipal User)
          {
              string currentUserId = User.Identity.GetUserId();
              return new MemberEntities().membershipusers.FirstOrDefault(m =&gt; m.AspNetUserId == currentUserId );
          }
      }
  </code></pre>
  
  <p>Or this way: </p>
  
  <pre class="lang-cs prettyprint-override"><code> public abstract partial class BaseController : Controller
  {
      private membershipuser _Member;
  
      public membershipuser Member
      {
          get { 
              if(_BASRaTMember == null)
              {
                 string currentUserId = User.Identity.GetUserId(); 
                  BASRaTMember = new BasratEntities().tbl_basrat_members.FirstOrDefault(m =&gt; m.AspNetUserId == currentUserId );
              }
              return _BASRaTMember; 
          }
          private set { _BASRaTMember = value; }
      }
  
  }
  </code></pre>
  
  <p>I'm thinking the Basecontroller method is best as I'm guessing if I called the extension method 5 times to check member properties it would query the database for the user 5 times. Or would it be better to somehow store it against the request? My sole intention is to reduce the database lookups for the requests after the user has been authenticated.</p>