Recently, due to project requirements, ASP needs to be studied. NET cache, but I have read books, msdn, and I am a little disappointed after the Internet. It is really a huge copy of the article in the world. We are talking about the few points, which are not organized, have no focus, and have no experience, so I decided to write an article by myself. Of course, I was not able to change this phenomenon, but I just wrote my own memo.
There are several points to note:
1. I personally think there are only two types of cache: ASP. NET page output cache and application data cache. This is what everyone thinks, but there is another person who divides the two parts into three or five types. This makes people feel a lot more.
2. The so-called control cache is actually the user control cache. It may be because I had a problem. At first I thought that the html control and web control can also be cached. Therefore, the definition name must be clearly defined.
3. there are two ways to implement cache: Writing Page processing commands at the top of the aspx page or writing code in the cs code is also called the cache API), one is static settings, one is dynamic settings. Some people on the Internet always like to talk about it and do not make it clear, so it is annoying.
4. As long as the cache is used, there must be cache dependencies. But some are not so obvious. In my articles, cache dependencies are generally explained separately as a chapter. This is a good thing, because cache dependency is very important in the cache advanced technology, however, this does not mean that some caches do not have cache dependencies.
Now let's get down to the truth. I only talk about common things.
ASP. NET page output cache. In fact, there is no big difference between the user control cache and it. Only one location cannot be used. Let's talk about it here.
Page command:
- <%@ OutputCache Duration="10" VaryByParam="*" VaryByControl="txtInput" %>
OutputCache is the command name. Duration is the cache Duration in seconds. VaryByParam is used to cache data. There are two special values: none indicates that the cache is not different from any parameter, that is, only one version is cached, indicating that the cache is different with any parameter, indicating that as long as the parameter changes, cache a new version. VaryByControl is used to cache data with the control name. The control here refers to a general server control, not a user control, otherwise unexpected results will appear.
Cache API:
Although the ASP. NET page output cache is similar to the user control cache in terms of page commands, it is different in terms of APIs.
Page cache api:
The System. Web. HttpCachePolicy class is mapped.
Response. Cache. SetCacheability (HttpCacheability. Public );
Response. Cache. SetExpires (DateTime. Now. AddSeconds (3 ));
The first sentence corresponds to Location, indicating where the cache is, where the public is, and where it is cached. nocache does not cache, private is the client cache, and there are several other options. We are concerned about the client, proxy server, and server.
The second sentence corresponds to Duration, indicating the cache Duration. This is the absolute time. At that time, the cache is canceled. Response. Cache. VaryByParams ["none"] = true;
VaryByParam is enclosed in brackets. Multiple parameters can be separated by semicolons. true indicates that this parameter is enabled. There is no corresponding VaryByControl.
Response. Cache. SetSlidingExpiration (true );
When this sentence is used, all the cache settings are disabled because this attribute is used for caching between browsers and Web servers, such as the proxy server, instead of for the Web server itself. this is specially designed. response. cache. setNoServerCaching () indicates that all current Server caches are canceled.
- Brief Introduction to ASP applications
- IScriptControl of ASP. NET
- ASP. NET Authentication Service
- Overview ASP. NET Security
- ASP. NET ISAPI