I have EntityTypes generated from a database using Entity Framework 4. I would like to use Cache to store some of these EntityTypes for performance reasons. Is it safe to do the following provided that the object will be used for read-only actions:
context.Students.MergeOption = MergeOption.NoTracking;
var students = context.Students.Where(s => s.Name == "Adam").ToList();
Cache["students"] = students;
Thanks.
One way is to use the EF cache provider. Another is to use your web server’s cache. But make sure you are not prematurely optimizing, or optimizing the wrong thing. Doing so will make your life miserable. It is generally better to optimize a web site with front end caching.