Hey, lazy bastard!! Actually, the MSDN is really good, I don't know where you came from.

Source: Internet
Author: User
Tags define insert
ASP.net provides you with a powerful, easy-to-use caching mechanism that allows you to store objects that require large amounts of server resources to be stored in memory. It is implemented by the Cache class, which is specific to each application and its lifetime depends on the lifetime of the application. When the application is restarted, an instance of its Cache object is recreated.

The Cache class is designed for ease of use. By using a key that is aligned with a value, you can place items in the Cache and retrieve them later. For an example of how to do this, see Add an item to the cache and retrieve the value of the cached item.

The cache class gives you a simple interface to customize cache settings, and it also provides powerful features that allow you to customize how items are cached and how long they are cached. For example, when there is a lack of system memory, the cache automatically removes infrequently used or unimportant items to allow memory to handle a large number of requests. This technique is called cleanup. This is a way for caching to ensure that non-current data does not use valuable server resources.

When scavenging is performed, you can instruct the Cache to give some items a higher priority than others. To indicate that a particular item is more or less important than other items, specify a CacheItemPriority enumeration value when you add an item by using the Cache.Add method or the Cache.Insert method.

When you add an item to the Cache by using the Add method or the Insert method, you can also establish an expiration policy for the item. You can define the lifetime of an item by using the Absoluteexpiration parameter, which is a DateTime type, allowing you to specify the expiration time for the item. You can also use the slidingexpiration parameter, which is the TimeSpan type. It allows you to specify the time to elapse before the item expires, based on the time that the item is accessed. Once the entry expires, it is removed from the cache. Attempting to retrieve the value will return NULL unless the item is added back to the Cache.

Set an expiration policy for volatile items stored in the cache (for example, items that often refresh data or those that are valid for a period of time only), and keep them in cache as long as the data for those items remains current. For example, if you are writing an application that tracks sporting scores by obtaining data from a regularly updated web site, you can cache the scores as long as the score on the source Web site does not change. In this case, you can set an expiration policy based on how often the Web site updates the score. You can write code to determine if the Cache is the most recent score. If the score is not up to date, the code can update the score from the source Web site.

Finally, ASP.net allows you to define the validity of cached items based on external files, directories, or another cache entry. These are called file dependencies and key dependencies. If the dependency changes, the cache entry fails and is removed from the cache. You can use this technique to remove items from the Cache when their data source changes. For example, if you write an application that processes financial data in an XML file and render it in a graphic, you can insert data from the file into the Cache and leave a dependency on the XML file. When the file is updated, the item is removed from the cache, and your application reads the file again, and then inserts a new version of the item.

Note that the Cache does not have information about the contents of the item it contains. It retains only references to these objects. It also provides a way to track their dependencies and set expiration policies.
For more information about how to take advantage of these features, see Adding Items to the cache.

Please see

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.