简体   繁体   中英

how to use sqlcachedependency with web.config

I want to get the data from cache if the data which is in the table on database.my webconfig file has the code;

<connectionStrings>
<add name="baglantiaditbluyeler" connectionString="Data Source=MURATAKARSU;Initial Catalog=verilerim;Integrated Security=SSPI"/>
 </connectionStrings>
 <system.web>
<caching>
<sqlCacheDependency enabled="true" pollTime="5000" >
<databases>
 <add name="verilerim" connectionStringName="baglantiaditbluyeler"/>
 </databases>
 </sqlCacheDependency>
  </caching>

and it is okay it runs as I want to.But If I want to cache the other table,should I insert same code with name of the other table.Namely should My code do as below?

 <connectionStrings>
<add name="baglantiaditbluyeler" connectionString="Data Source=MURATAKARSU;Initial Catalog=verilerim;Integrated Security=SSPI"/>
<add name="baglantiaditblSorular" connectionString="Data Source=MURATAKARSU;Initial Catalog=verilerim;Integrated Security=SSPI"/>
 </connectionStrings>
 <system.web>
<caching>
<sqlCacheDependency enabled="true" pollTime="5000" >
<databases>
 <add name="verilerim" connectionStringName="baglantiaditbluyeler"/>
 <add name="verilerim2" connectionStringName="baglantiaditblSorular"/>
 </databases>
 </sqlCacheDependency>
  </caching>

My code runs but I want to teach is it true way.

The setting you specified in web.config is actually a PER DATABASE setting. means, for each database, you specify the settings once. If the 2 tables are from same database, then there is NO need to specify twice.

If the 2 tables are from different database, you need to specify the settings for each database seperately. The <databases> element in web.config takes name of a database in <add name="... settings. it doesn't takes the name of tables.

Since you need to cache other table, there are two types of dependencies for SQL.

1.) The first uses polling, which is table based.

2.) The second takes commands and therefore the cache is dependent on the query being executed.

One very brilliant tutorial on using these 2 types of dependencies in SQL is here. . This link also explains the settings in web.config for SqlCacheDependency.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM