Accepted answer

Don't cache a queryable. They're lazily evaluated, and the chances are high that (1) the context won't be there when you read the cache, so enumerating it will die, and (2) it isn't serializable, so it won't work with distributed caches.

If you have to cache a list of something, put it into an array of primitive types.


HttpRuntime.Cache["test"] = testObject.ToList();

IList<string> attributes = (IList<string>)Cache["test"];

Related Articles