Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the three types supported by ASP.NET Cache?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

What are the three types of ASP.NET Cache support, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

ASP.NET Cache supports three types

If you want to write a quick overview of technology, you may have written too much. The purpose of the technology outline is to describe the main points of the technology in the fastest and simplest way, and it is also the most efficient way of knowledge dissemination that I hope.

1. Page / control cache

2. Application-level cache

3. Browser client cache

From the point of view of implementation, the page / control cache and application-level cache in ASP.NET Cache are stored in the server memory, which may be deleted in advance before expiration as the memory becomes tight. (the nature of cache determines that these contents can be safely deleted.) The cache of the browser client is stored in the cache of the client browser. For example, the temporary folder of IE plays the role of cache. Every time a user requests a page, the browser will first check the cache to see if there is any cache content that has not expired yet, and if so, read directly from the cache to skip the network transmission.

Here's a demonstration of how to write it in ASP.NET:

1. The page / control cache in ASP.NET Cache can be declared in the aspx,ascx file or in code behind.

<% @ OutputCache Duration= "# ofseconds" Location= "Any | Client | Downstream | Server | None | ServerAndClient" Shared= "True | False" VaryByControl= "controlname" VaryByCustom= "browser | customstring" VaryByHeader= "headers" VaryByParam= "parametername" CacheProfile= "cache profile name | 'NoStore=" true | false "SqlDependency=" database/table name pair | CommandNotification "% >

The main parameters are:

Duration: the time in which cache is valid (in second)

Shared: valid only for controls, whether multiple pages can share this cache without each page maintaining its own cache for the control when the control can be applied to multiple pages at the same time.

VaryByControl:cache varies with the ID of the control

VaryByCustom:cache varies with a user-defined variable, which is specified here, and should then be implemented in Global.ascx:

Public override string GetVaryByCustomString (HttpContext context, string custom)

The custom parameter of this declaration is the variable declared in OutPutcache. Different custom contents are represented by returning different string values for different cache parameters in this function.

VaryByHeader and VaryByParam,CacheProfile are also set to different versions of cache.

NoStore indicates that the contents of cache are not allowed to be written to storage devices other than memory, which is the need for more secure content.

SqlDependency is related to the database.

2. Application-level cache in ASP.NET Cache

Can only be obtained in code behind, characterized by the ability to implement any cache logic you need.

Can be obtained through Page.Cache, and the name of the class is System.Web.Caching.Cache

3. Browser client cache in ASP.NET Cache

It is only available in codebehind and can be specified through Response.Cache, which is a HttpCachePolicy object.

In addition: you can specify a TimeSpan as the cache time, do not have to convert to seconds each time.

PublicTimeSpan (longticks); publicTimeSpan (inthours,intminutes,intseconds); publicTimeSpan (intdays,inthours, intminutes,intseconds); publicTimeSpan (intdays,inthours, intminutes,intseconds,intmilliseconds)

If you want cache to keep one hour, one minute and one second, you can directly

New TimeSpan (1 ~ (1))

Without having to calculate first

1 hour, 1 minute, 1 second = 3600 hours, 60 seconds, 1 seconds, 3661 seconds, and then pass 3661 as the validity period.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report