ASP. NET page Cache

Source: Internet
Author: User
ASP. NET page cache [transfer]

There are two types of Web Cache Technology in ASP. NET: Output cache and data cache!
The output cache stores the dynamic output generated by a request in the memory. The page cache is the output cache, that is, the entire page is cached, if an ASP. if you store frequently accessed pages in the memory, the performance will be improved as long as the request page is cached, in the future, no page compilation instance will be created for page requests (get and head requests), but will be obtained directly from the memory!
By default, the output cache option is opened, but not all pages are cached. You need to specify which pages need to be cached!
For cached pages, get and head requests are directly retrieved from the cache entry and returned to users, while page return (POST request) is usually a dynamic page generation, that is, reload, and get. HEAD requests are different. Please note that !!
The output cache has a page cache Expiration/effective time policy, that is, if a page is specified with a cache time of 60 seconds, the page will be cached in the memory within these 60 seconds, if it exceeds 60 seconds, the page is clearly cached in the memory. In this way, the expiration policy is called "forced expiration ".
There are two ways to set the page output cache: Advanced and low.
Advanced Settings are implemented through the page command and the lower-level settings are implemented through the cache API, that is, the httpcachepolicy class. Below I will write these two methods:
Page command: <% @ outputcache duration = seconds %>
After adding this command to the page, the returned results for requests to the page are the same within the specified number of seconds!
This setting has a total of five available features. In fact, only the duration and varybyparam features are required.
1. Control the page cache location
Location: three different locations (browsers, proxy servers, and web servers) that can cache resources ). When writing a page, you can use this feature to specify the location where the page output cache is allowed. This feature has five possible settings
(1) Any default value, that is, it can be cached in the client browser, in the proxy server, or in the web server itself
(2) The client can only be cached on the client (that is, the browser sending the request)
(3) downstream output cache can be stored on http1.1 cache devices (such as proxy servers)
(4) The server output cache will be stored on the Web server.
(5) Disable output cache for none
2. Control the lifecycle of pages in the cache
Duration specifies the period in which the cache exists, in seconds
3. Use parameters to enable different versions of the page
Varybyparam specifies that different versions of the same page can be cached. You can set a variable name for passing parameters on the page, and then cache the page.
Different values can be used to cache different versions. You can also set it to "*" to cache every possible version of the page. However, this is an extremely memory-consuming approach, not
A good idea to improve performance! You can also set this parameter to "NONE", that is, do not cache different versions of the same page based on the parameter.
4. Other methods for enabling different pages
The varybyheader and varybycustom features are similar to those of varybyparam: they allow you to specify when to create a new Cache version of the page.
Varybyheader: allows us to cache different versions of the page based on the list of HTTP headers separated by semicolons (not used yet,)
Varybycustom: this feature is set to "Browser", which allows us to cache different versions based on the browser name and main version information. You can also set it to
Customize the method name to implement our own logic and control the cached version.
Cache API commands:
// Specify that the page output cache expires in the next 10 seconds
Response. cache. setexpires (datetime. Now. addseconds (10 ));
// Specify that all users have the right to access the cache
Response. cache. setcacheability (httpcacheability. Public );

From: http://www.blogcn.com/user52/it1/blog/29308733.html

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.