开发者

Is there an easy way to use ASP.NET caching with Entity Framework 4.1 Code First?

We are using EF code first with the App Fabric cache on Windows Azure (although, I think the question is really more generic since we are using it as an ASP.net caching provider开发者_如何学JAVA). Is there an easy way to enable caching of DBset objects? Our db is small and not updated very frequently, so ideally we could cache the entire database in memory, and use some ttl expiry to refresh object sets. Any advise from someone with experience caching using EF code first would be great.


Don't do that. If you want to cache data, extract them to separate Lists and cache them separately. Caching DbSet means caching DbContext which I would promote to anity-pattern in Entity framework. Problems with identity map and unit of work are described in linked answer. Another problem is that there is no real refresh. If you really want to refresh data you must dispose context and create a new one. Context is also not thread safe so sharing it among multiple requests can cause unexpected results.


Maybe you could use this solution, but I never used it with Azure:

EF Caching Provider

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜