. NET Page Caching

Source: Internet
Author: User

aspx.net Page Cache
Page caching is very simple to use, just add a statement at the top of the ASPX page <%@ OutputCache duration= "" varybyparam= "None"%>
This way, the contents of the entire page are cached, the ASP. NET code in the page, the data source is not run during the cache, and the content of the cached page is output directly.
Page caching is for all visitors to this page. So the pressure on the database for 1 visitors and 10,000 visitors, one visit, and 1 million visits is the same.

duration= "This means that the specified cache time is 60 seconds, which can be set according to the circumstances, the cache will expire after this time, and the second generation is cached for 60 seconds, and so on.
varybyparam= "None"It means to set the parameterless cache (which is discussed below)
But for some parameters of the page, such as the News content page (for example, for access to each news content page path is http://test.com/ViewNews.aspx?id=1, the Server page cache is unable to automatically read the value of this parameter ID), If set as above, will only be cached? Id=1 's news page, because id=2,? id=3 is just the different parameters of the page, in order to cache a variety of news pages, you can setvarybyparam= "id", which represents a separate cache for different ID parameters. If there are multiple deterministic cache parameters, separate the parameter names with semicolons, such asvarybyparam= "Id;number"。
If you want to create a different cache for any of the different query strings, set thevarybyparam= "*", it is sufficient to set the "*" under normal circumstances.
These two parameters are required and cannot be defaulted. There is another important parameter.diskcacheable= "True|false"If you want to put the cache on the hard disk, if set to False then the cached data will be put into memory.
Note here, if the page data is very small, you can put the cache data into memory, if the data is larger than the best to put on the hard disk, otherwise it will consume a lot of memory affect the server to run, if the data cache to the hard disk, remember to set the value of the duration largerduration= "3600", if the set is too small, the server will be too frequent write data on the hard disk will degrade performance, if in memory cache data duration "" Do not set too long, of course, the specific length of time to everyone to try to know.

MVC Page Caching

To implement page caching in an ASP. NET MVC Project, configure the following nodes in Web. config:

  <system.web>    <Caching>      <outputcachesettings>        <outputCacheProfiles>          <Addname= "Postcache"Duration= "3600"sqlDependency= "Postcachedependency:posts"VaryByParam="*" Location= "ServerAndClient"/>        </outputCacheProfiles>      </outputcachesettings>    </Caching>  </system.web>

. NET Page Caching

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.