我的確有一個問題:我正在研究ASP.Net Web窗體和C#應用程序,並且我使用gridView來顯示錶中的數據,所以我決定緩存。SqlDependency和SqlCacheDependency之間的差異
我做了
aspnet_regsql -ed -E -d Store
aspnet_regsql -et -E -d Store-t Customers
,並在web.config
修改:
<caching>
<sqlCacheDependency pollTime="2000" enabled="true">
<databases>
<add name="Store" connectionStringName="StoreConnectionString"/>
</databases>
</sqlCacheDependency>
</caching>
但現在我必須決定是否使用SqlDependency
<%@ OutputCache Duration=」600″ SqlDependency=」Store:Customers」 VaryByParam=」none」 %>
或者使用SqlCacheDependency
private void BindData() {
if (Cache["Users"] == null) {
SqlCacheDependency dep = new SqlCacheDependency("Store", "Customers");
string connectionString = ConfigurationManager.ConnectionStrings[
"ConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT FirstName, LastName " +
"FROM Users", myConnection);
DataSet ds = new DataSet();
ad.Fill(ds);
Cache.Insert("Cust", ds, dep);
}
gvUsers.DataSource = Cache["Cust"] as DataSet;
gvUsers.DataBind();
}
請您告訴我SqlDependency
和SqlCacheDependency
之間有什麼區別,哪個更適合我的代碼?