Cache is used to save your data, so that your applicationProgramFaster access. The cache can be allocated to many machines according to your needs, and developers do not need to worry about which machine the data is stored. To achieve ultra-fast performance, you can even copy the cache to the calling client (local cache) at the expense of data consistency ). The stored data can be any serialized. Net object.
The purpose of using cache is to improve the performance and scalability of your applications. Appfabric supports explicit and implicit Cache Usage to improve scalability and performance. If you are an ASP. NET developer, you should be familiar with implicit and explicit cache usage. Explicit Cache Usage allows you to add, delete, and manage data items in the cache programmatically through the cache API provided by appfabric. This is a very powerful tool to help you customize the cache policies and usage modes of application data. However, you need to understand the data cache principles. The default cache policy can be used in common scenarios. Two examples of implicit caching are ASP. NET session Status and HTML page cache (that is, output cache ).
With the ASP. NET Provider Model, developers can choose from three session providers: inproc, StateServer, and sqlserver. When using appfabric cache, the fourth session provider is technically feasible, but be careful not to confuse sessions with cache. Cache is used to improve performance, and session is used to make the application reach a certain state.
The appfabric cache session provider for ASP. NET uses its distributed cache (which may have high availability) as the repository for ASP. NET sessions. This function is transparent and does not need to be modified.Code. With such a program, ASP. NET sessions can be kept available when the web server crashes or is offline, because sessions are stored in the appfabric cache.
ASP. NET 4.0 redesigned it and provided an outputcacheprovider for developers to expand it. However, by default, it still uses system. Web. caching. cache for caching. For how to use the output cache of ASP. NET 4.0, seeScottguOfVs 2010 and. Net 4.0 series: extensible output cache in ASP. NET 4.
ASP. NET development team released on codeplexASP. NET 4 providers for appfabric cachingThere are two providers, ASP. NET session Status and HTML page cache (that is, output cache ):
- Session state:Microsoft. Web. distributedcachesessionstatestore
- Output caching:Microsoft. Web. distributedoutputcache
Currently, these two providers are not officially released, but are only released inCommunityTesting and feedback, cannot be directly used in the production environment. However, appfabric has an ASP. NET session State provider (Windows Server appfabric caching). For more information, see http://msdn.microsoft.com/en-us/library/ee790859.aspx.
The usage is as follows:
1. Add the cache configuration section to the Web. config file of ASP. NET 4.0, as shown below:
<Caching>
<Outputcache defaultprovider = "appfabricoutputcache">
<Providers>
<Add name = "appfabricoutputcache" type = "Microsoft. Web. distributedoutputcache, Microsoft. Web. distributedcache" hostname = "localhost" cacheport = "22233" cachename = "session"/>
</Providers>
</Outputcache>
</Caching>
2,Use Microsoft. Web. distributedoutputcache
1) Configure in the configuration file and use the custom implementation as the default output cache support. Please refer to the configuration 1.
2) Specify the provider name in usercontrol and change the name to be defined in Web. config. For example:
<% @ Control Language = "C #" autoeventwireup = "true" codebehind = "iamusercontrol. ascx. cs" inherits = "outputcachetest. iamusercontrol" %>
<% @ Outputcache duration = "3000" providername = "aspnetinternalprovider" varybyparam = "NONE" %>
Note that the provider name can only be specified in usercontrol. It is not allowed in the page declaration. Web is used by default in page. the defaultprovider configured in config, but we can use the methods described in 3) to use different outputcacheprovider for different pages.
Similarly, if I add the [outputcache] feature to an ASP. when any action method of the net MVC controller is used, the content will be cached and saved by using my scottoutputcache provider:
3) You can overwriteGetoutputcacheprovidername ()Method, dynamically specify the output cache provider to use based on each request. As shown in the following. aspx "Web page I want to use built-in, with memory ASP. net output cache provider, and then for all other requests, I want to use registered on the web. the provisioner In the config file: in global. in the asax file, override the getoutputcacheprovidername (httpcontext context) method and return different implementation names based on context. The following example
ASP. NET 4.0 new features use custom outputcache provider
Vs2010] new feature of ASP. NET 4.0: Output cache provider
Construct and use custom outputcache providers in ASP. NET