title: Entity Framework & MemoryCache
body: <p>I have an n-tier application ASP.NET MVC. I use entity framework in DAL.
  So i decided to use cache layer in dal for up app's performance. I've implement it but there is a problem. I put entity to memory cache first request after that when second request i try to get entity from cache it's throw object disposed error. I know this error normal because i can't it from cache. But i couldn't think it.
  What can i do? Should i use business object in dal or?</p>
  
  <p>"The ObjectContext instance has been disposed and can no longer be used for operations that require a connection"</p>
  
  <pre><code>    public IQueryable&lt;Category&gt; GetAll()
      {
          var cacheKey = string.Format("{0}_{1}", "CategoryRepository", "GetAll");
  
          var isExists = _cache.Contains(cacheKey) &amp;&amp; Const.CacheIsActive;
          if (isExists)
          {
                 //At here error: "The ObjectContext instance has been disposed and 
                 //can no longer be used for operations that require a connection"
              return _cache.Get&lt;IQueryable&lt;Category&gt;&gt;(cacheKey);
          }
          else
          {
              var obj = _db.Categories;
              _cache.Add(cacheKey, obj);
  
              return obj;
          }
      }
  </code></pre>