Measure the test taker's understanding about the cache function of. NET 4.0.

Source: Internet
Author: User

Many introductions on the new features of. NET 4.0, the enhancement of the cache function will certainly not be ignored. In many documents. in NET 4.0, the cache function is enhanced mainly in terms of scalability, changing the limitations that can only use memory for caching, you can flexibly switch the cache media by modifying the configuration without changing the code. The Cache Provider is scalable. developers can conveniently store the Cache in files, or expand the distributed Cache. However, because System. web. caching. the existence of the Cache object keeps me updated. NET 4.0 and the existing System. web. caching. the Cache relationship is confusing. Through the past two days of research, I have slowly unlocked this layer of confusion.

Review of cache functions before. NET 4.0

In fact, no. NET Framework cache Framework exists before. NET4.0. It is actually a cache Framework designed for ASP. NET. In ASP. NET, there are two types of Cache: Output Cache and data Cache. The output cache is used to cache HTML pages or some HTML (User Control) pages that have been generated. This reduces the number of static content generation times and increases the request response time. Data caching is a commonly used and rarely updated data that developers want to cache in the memory to reduce the number of data reads and improve program performance. Both caches use System. Web. Caching. Cache to Cache data.

System. Web. Caching. Cache

It is a memory cache implementation and does not provide expansion of the cache media. Data is directly cached in the memory. This object is generally not instantiated by ourselves. Generally, in a Page, we directly use Page. Cache for Cache operations without worrying about how it is instantiated. To use the cache outside the page, we can use the global System. web. context. current. you can also use System. httpRuntime. cache. In fact, if we track the relationship between these objects through Reflector, it is not difficult to find that although there are Cache objects in so many places, they are actually referencing the same object, that is, HttpRuntime. cache object. Note that System. httpRuntime. the Cache can be used not only in the Web environment, but also in any program, including WinForm and Console Application, provided that you reference System. web. dll. This means that the System. Web. Caching. Cache object can be completely separated from the System. Web namespace and exists as an independent Cache framework. This is also the first thing I am confused about: Will System. Web. Caching. Cache change the existing implementation and directly use the new Scalable Cache framework?

Full resolution of cache functions in. NET 4.0

The Cache function of. NET 4.0 is composed of three parts: System. Runtime. Caching, System. Web. Caching. Cache and Output Cache. The three and their previous relationships are parsed as follows:

System. Runtime. Caching

This is a cache framework added in. NET 4.0, which exists in the assembly System. Runtime. Caching. dll. The System. Caching mentioned in this PPT refers to it. It is a Scalable Data Cache framework and provides built-in memory cache implementation for MemoryCache. However, it is not so extensible in use. In addition to providing the abstract class ObjectCache, it does not provide a scalable configuration scheme. We cannot switch the implementation of ObjectCache through the configuration scheme, we must hard encode the ObjectCache implementation in the Code:

ObjectCache objectCache = MemoryCache.Default;//

The Configuration in System. Runtime. Caching. Configuration is also for MemoryCache. These configurations indicate the memory usage quota scheme for each MemoryCache instance and the quota check cycle. The instance name of MemoryCache. Default is "Default", so that we can change the memory quota of MemoryCache. Default through the following Configuration:

<system.runtime.caching>    <memoryCache>        <namedCaches>            <add name="Default" cacheMemoryLimitMegabytes="10"  pollingInterval="00:02:00"/>        </namedCaches>    </memoryCache></system.runtime.caching>

The cache expiration Policy is similar to other cache frameworks. web. caching. the difference between Cache is that the name is not CacheDependency, but ChangeMonitor, and a Cache dependency policy based on files and directories is provided.

System. Web. Caching. Cache

I have been searching for the answer. Check whether the underlying System. WebCaching. Cache is changed to System. Runtime. Caching. The result is that it has not changed.

Output Cache

The Output Cache has changed a lot. Versions earlier than ASP. NET 4.0 directly use System. Web. Caching. Cache to Cache HTML fragments. In ASP. NET 4.0 was redesigned to provide an OutputCacheProvider for developers to expand, but it still uses System by default. web. caching. cache. For how to use the Output Cache of ASP. NET 4.0, refer to ScottGU's article.

The above results show that System. Runtime. Caching and Output Cache are scalable. In addition, there is no relationship between the two, and the extension interfaces provided are very different and need to be implemented separately. System. Runtime. Caching can be used to replace the Enterprise Library Cache Application Block. In addition, the distributed Cache framework released by Microsoft, Windows Server AppFabric, should have provided System. Runtime. Caching extensions.

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.