Asp.net server and client cache

Source: Internet
Author: User

The server cache stores data in the server's memory, while the client cache stores the data in the browser.

If a page on the server has a large access volume and is subject to frequent changes, it is more appropriate to use the server cache, so that you can access the situation where too many database connections are created at the same time.

If a page on the server has a large access volume, but the content remains unchanged, or remains unchanged for a long time, you can use the client cache or the server cache.

The server cache should not be abused, but should be used according to the actual situation. Otherwise, it will not improve the efficiency, but it will be worse than not using the cache.
Client Cache misuse may cause users to browse a fixed page for a long time

Usage
Server:
ASP. NET has three types of Web ApplicationsProgramCache used:
1. Output cache: the dynamic response generated by the cache request.
2. segment cache: The corresponding parts generated by the cache request.
3. Data Cache: mix arbitrary objects in programming mode.

Output cache: (the cache is absolutely expired)
Improves the throughput of requests/responses by caching content generated from dynamic pages. By default, the output cache is enabled,
However, the output from any response is not cached unless explicit operations are performed to make the response cacheable.
To meet the output cache conditions, it must have an effective Expiration/validity policy and a public cache can
Visibility. After the output cache is enabled, an output cache item is created when the first GET request to the page is sent. Subsequent get or
The head request is provided by the output cache service until the cache request expires.
The following command activates the output cache when the response is received:
<% @ Outputcache duration = "60" varybyparam = "NONE" %>

Page segment cache: (separate cache)
<% @ Outputcache duration = "120" varybyparam = "id1; Id2" %>
The varybyparam attribute feature is very powerful, allowing the user control author to instruct Asp.net to cache/store on the server
Output multiple instances in the cache region.
Fragment caching also supports the varybycontrol attribute. The varybyparam attribute is based on the name sent using post or get.
/Value pairs change the cache results, while the varybycontrol attribute changes the cache fragments through controls in the user control.

Page data cache:
Put data items into the cache:
Cache ["mykey"] = myvalue;
Retrieve data from the cache:
Myvalue = cache ["mykey"];
If (mycache! = NULL)
{
Displaydata (myvalue );
}

Client Cache:

<% @ Outputcache duration = "10" varybyparam = "NONE" varybycustom = "Browser" %>

In addition, the server cache is used when multiple users simultaneously request the same page or data.

The client cache is used for multiple accesses to the same page or data by the same user.

The active cache can greatly improve the website access speed, especially when the traffic volume is large.

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.