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?
"The ObjectContext instance has been disposed and can no longer be used for operations that require a connection"
public IQueryable<Category> GetAll()
{
var cacheKey = string.Format("{0}_{1}", "CategoryRepository", "GetAll");
var isExists = _cache.Contains(cacheKey) && 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<IQueryable<Category>>(cacheKey);
}
else
{
var obj = _db.Categories;
_cache.Add(cacheKey, obj);
return obj;
}
}