我的数据库中有一个税表,可能每年更改一次。我们的 asp.net 应用程序具有根据客户所在的省/州查询数据库中税费的计算。我想避免那些往返。有没有办法可以在 Entity Framework 4 中使用缓存?因此,我想要基于 edmx 中的税表的实体,但是当我对其执行 LINQ 查询时,我不希望它进入数据库,除非缓存已过期。我将如何实现这个目标?
我以前没有使用过 ASP.NET 数据缓存,因此非常感谢有关该概念的一些详细信息。我已阅读有关应用程序数据缓存的 msdn 文档,但我只是想知道如何以优雅的方式使其与 EF4 一起工作。
I have a taxes table in the database which changes maybe once a year. our asp.net application has calculations that query the database for taxes based on the customer's province/state a lot. I would like to avoid those round trips. Is there a way I can use caching with Entity Framework 4? So I want the entity based on the taxes table in my edmx, but when I perform LINQ queries against it, I don't want it to go to the database unless the cache has expired. How would I accomplish this?
I haven't worked with asp.net data caching before, so some details on the concept would be highly appreciated. I have read the msdn documentation on application data caching, but I'm just wondering how to make this work with EF4 in an elegant manner.
发布评论
评论(1)
您可以为此使用文件基础缓存。就像您必须在表上创建一个触发器,它将修改特定位置上的文件,然后您可以从 ASP.NET 代码添加文件上的缓存依赖项。因此,除非表中发生任何更改,否则您必须从缓存中获取数据,如果文件发生更改,那么它将验证缓存并从数据库中获取数据。
或者,
如果您使用 SQLServe 作为后端,则可以使用 SQL 缓存依赖功能。
以下是一些可能对您有帮助的链接。
http://www.15seconds.com/issue/031229.htm
http://www.c-sharpcorner.com/uploadfile/vishnuprasad2005/implementingcachinginasp .net11302005072210am/implementingcachinginasp.net.aspx
以下是实体框架中对缓存的一些支持
http://blogs.msdn.com/b/efdesign/archive/2008/07/09/transparent-caching-support-in-the -entity-framework.aspx
http://www.andrewdothay .net/blog/2009/01/28/LINQAndTheSqlCacheDependency.aspx
You can use file base caching for that. Like you have to create a trigger on the table which will modify files on a specific location and then you can add cachedependancy on file from asp.net code. So until and unless any changes occurred in table you have to fetch data from the cache if file changes then it will validate cache and data will be fetch from the database.
Or
You can SQL Cache dependancy feature if you are using SQLServe as your backend.
Here are the some links that might help you.
http://www.15seconds.com/issue/031229.htm
http://www.c-sharpcorner.com/uploadfile/vishnuprasad2005/implementingcachinginasp.net11302005072210am/implementingcachinginasp.net.aspx
here are some support for caching in entityframework
http://blogs.msdn.com/b/efdesign/archive/2008/07/09/transparent-caching-support-in-the-entity-framework.aspx
http://www.andrewdothay.net/blog/2009/01/28/LINQAndTheSqlCacheDependency.aspx