嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
1.开启数据库缓存依赖功能(开启对数据库中表Article和ArticleType的缓存)
(注:)如果要配置SqlCacheDependency,则需要以命令行的方式执行。
aspnet_regsql.exe工具位于Windows\\Microsoft.NET\\Framework\\[版本]文件夹中。
aspnet_regsql -C "data source=WIN-2FNH16TMA0F\HZM;initial catalog=Sngovweb_sta3;user id=Sngovweb_sta;password=sngo1234...." -ed -et -t "dbo.Article"
aspnet_regsql -C "data source=WIN-2FNH16TMA0F\HZM;initial catalog=Sngovweb_sta3;user id=Sngovweb_sta;password=sngo1234...." -ed -et -t "dbo.ArticleType"
2.配置Web.config文件
<connectionStrings>
//实体框架生成的数据库连接字符串
<add name="SimpleNewsContext" connectionString="metadata=res://*/SimpleNews.csdl|res://*/SimpleNews.ssdl|res://*/SimpleNews.msl;provider=System.Data.SqlClient;provider connection string="data source=WIN-2FNH16TMA0F\HZM;initial catalog=Sngovweb_sta3;persist security info=True;user id=Sngovweb_sta;password=sngo1234....;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
//新增数据库连接字符串
<add name="test" connectionString="data source=WIN-2FNH16TMA0F\HZM;initial catalog=Sngovweb_sta3;persist security info=True;user id=Sngovweb_sta;password=sngo1234....;multipleactiveresultsets=True;"/>
</connectionStrings>
<system.web>
<caching>
<sqlCacheDependency enabled="true" pollTime="10000">
<databases>
<add name="SimpleNews" connectionStringName="test" />//这个连接字符串名称不是实体框架生成的那个,而是自己手动添加的
</databases>
</sqlCacheDependency>
</caching>
</system.web>
3.在控制器的方法上打上[OutputCache]标签
[OutputCache(Duration = 86400, SqlDependency = "SimpleNews:dbo.Article;SimpleNews:dbo.ArticleType")]
public ActionResult Index()
{
return View();
}