Understanding about Cache Usage and understanding about Cache Usage

Source: Internet
Author: User

Understanding about Cache Usage and understanding about Cache Usage

First of all, the advantage of caching is that the cache stores data in the memory and extracts the data from the memory when needed (compared with the data obtained from the hard disk, the cache speed is much faster) prompt speed

 

Cache category: Page cache data source cache (permanent and time-limited) Dependency items cache database dependency Cache

 

Page cache:

Implementation Code

He will cache the entire page and then judge whether the page to be accessed is cached between 7th events and 8th events in the pipeline. If yes, he will directly return to the cache page. The pipeline does not need to be completed. improved speed

Note: this can only be used on pages that remain unchanged most of the time. page caching cannot be used on pages with large changes (especially when accuracy is pursued)

 

Data Source cache: for example, put the data in the displayed list into the cache.

Below is the code

When to use: on a page, this data source is not changed frequently and needs to be extracted from the database multiple times. This cache is used when other data sources need to be changed.

When Application_start () is started for the first time, the data source will be directly retrieved from the cache after it is saved to the cache (when the display needs to be changed, the data will be automatically written to the cache when the background changes the relevant data)

 

The above permanent cache is the creation of a time-limited cache.

 

The cache with time restrictions seems to be slightly different from the above permanent cache, but it is more suitable for data sources with moderate data conversion frequency.

 

Dependency cache: in 2, dependency is a dependent file, and dependency is a database.

Dependent files are usually dependent on configuration files or xml files (because they are the data read from the xml files)

Only the dependent file changes are cached and released.

For example, if you depend on an xml file and retrieve data from the xml file, the cache will be released when the xml file changes (increases or decreases) and the data will be re-read into the cache.

This may seem very convenient for you to change. I also avoided reading data from the xml file multiple times without significance, but you need to think about why the system will know that you have changed and you are definitely constantly monitoring. This may be a waste of efficiency.

 

The database dependency is also constantly monitoring the database until the Database Change Notification Program is wasted for convenience.

Below is the code

File dependency

Database dependency

 

Database cache dependency
1. database cache dependency
-S server name-E integrated Authentication-ed startup-d database name-et specifies the buffer dependent table name-t table name
Run the command in the command line of vs2010(switch to the directory where aspnet_regsql.exe is located)
Aspnet_regsql-S.-E-ed-d bjhksj-et-t HKSJ_USERS

Aspnet_regiis

Cache dependency disable this database
Aspnet_regsql-S.-E-dd-d bjhksj


2. Database-dependent web. config Configuration
<System. web>
<Caching>
<SqlCacheDependency enabled = "true">
<Databases>
<Add name = "HeimaRegulation" (name of the dependent database) connectionStringName = "connectionString" (name of the dependent connection string) pollTime = "500"/>
</Databases>
</SqlCacheDependency>
</Caching>


3 Write Cache

3. System. Web. Caching. SqlCacheDependency dep = new System. Web. Caching. SqlCacheDependency ("HeimaRegulation", "Branch ");
Cache. Insert ("list", list, dep, System. Web. Caching. Cache. NoAbsoluteExpiration, System. Web. Caching. Cache. NoSlidingExpiration );

 

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.