Asp.net cache-data dependent Cache

Source: Internet
Author: User

Since the project is useful to the knowledge of cache, here is a summary.

Run aspnet_regsql-c "Server = (local) \ tadb; database = abico; uid = sa; Pwd ="-ed-et-T "events" in the vs2008 VC window"

A aspnet_sqlcachetablesforchangenotification table will be created in your database, and there are several stored procedures.

 

Configure the cached information in Web. config.

Configuration Information

<Appsettings/>
<Connectionstrings>
<Add name = "testcache" connectionstring = "Data Source = 127.0.0.1; initial catalog = abico; user id = sa; Password = 135246" providername = "system. Data. sqlclient"/>
</Connectionstrings>

 

 

Code

<System. Web>
<Caching>
<Sqlcachedependency enabled = "true" polltime = "1000">
<Databases>
<Add name = "abico" connectionstringname = "testcache"/>
</Databases>
</Sqlcachedependency>

 

 

Polltime indicates the database polling time. The default value is 1 minute, in milliseconds. This parameter is very important. Similar to the timer function, the application will periodically poll your database based on this time to check whether your table has been updated.

 

If it is not configured in Web. config, you can also write it in the sqlcachedependencyadmin class.

To Cache multiple tables:

1) In the aspnet_sqlcachetablesforchangenotification table, a new record tabname is the table you want to cache.

2) sqlcachedependencyadmin. enabletablefornotifications (constring, "qx_user"); the first parameter is the connection string, and the second parameter is the name of the table to be cached.

The main point is that you need to write the table name for your cache dependency.

Sqlcachedependency Dep = new sqlcachedependency ("abico", "qx_user"); abico: Database Name, qx_user: Table name.

------------------------------------------------------

The cache I understand is that. Net makes a timer to poll the database according to the polltime, calls the stored procedure, and knows the aspnet_sqlcachetablesforchangenotification information of the table, which contains the changeid. When the changeid changes, the callback function is triggered if a callback function exists. If no, the existing cache is deleted.

-------------------------------------------------------

Demo download/files/86188281/cachetest.rar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.