开发者

How to cache result/data sets in EF 4.1?

I have a view in MVC3 application that calls a stored procedure (that takes a while to execute) to populate a grid on a view and would like to cache that data somehow? Not familiar with EF cacheing but I would actually like to somehow run the query possibly on a background thread in the background on start up so that when the user clicks on this particular view (which is a common data view the usere want to see) results are fast and cached as dispalyed in the webgrid

Any information would be greatly app开发者_开发问答reciated. Thanks!


Use the repository pattern to request your data entity. Inside your repository class cache the result in the MemoryCache (a specific type of cache in .net). Any time you then request the object the repository class knows to get it from te cache or not and the caller doesn't need to know anything about the caching. I would use either code first OR the poco templates to not have any baggage stored from other dependencies .

For POCO - you can either use the EF POCO Templates, or a code first model to give you poco classes without the EF baggage. Let me know if you have any specific q's on these steps and I can go into more detail. If you need to take a while loading this on application start, another thread is definitely the way to do it as any long running Application_start code in the main thread can cause a deadlock. A more basic approach per user is to put the object in the users session but that's indeed up to you. There is no EF caching as part if the EF framework that exists outside of the ObjectContext lifetime. Another method is to handle this in the controller method as shown here: How to cache mvc3 webgrid results (so that col sort click doesn't?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜