What is the best way to implement an object cache with Entity Framework?
Posted
by Harshal
on Stack Overflow
See other posts from Stack Overflow
or by Harshal
Published on 2010-05-03T04:34:34Z
Indexed on
2010/05/03
4:38 UTC
Read the original article
Hit count: 302
Say I have a table of "BlogPosts" in a database and i want to be able to cache the ones that were retrieved already in memory, for further reads, I can just use a standard hashtable type memory cache like System.Web.Caching.Cache, but if i then need to update a property on one of these blog posts e.g. blogPost.Title and update the record in DB, i cannot do this without fetching it again from database as the Entity Framework context used to fetch this record when it was loaded into my cache is already disposed?
How do I write code so that I am getting an object from my cache, updating one property and just calling the SaveChanges method without incurring an extra read.
© Stack Overflow or respective owner