Windows Server appfabric cache (Microsoft Distributed cache solution)

Source: Internet
Author: User
This section describes the features of Windows Server appfabric. Code Refer to msdn. (Similar product memcahed) Windows Server appfabric extends Windows server to think Web Applications Program And intermediate layer services provide enhanced hosting, management, and caching functions. The appfabric hosting feature adds Service Management Extensions to Internet Information Service (IIS), Windows Process activation Service (was), and. NET Framework 4. These include managed services and managed management tools that make it easier to deploy, configure, and manage services based on Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF. The appfabric cache function adds a distributed in-Memory Object cache to Windows Server, making it easier to expand high-performance. Net Applications (especially ASP. NET applications. With the appfabric cache function, you can merge the memory capacity of multiple computers into a unified cache cluster, which helps you easily and cheaply expand. NET applications. These functions include the cache service, cache client, and cache management tools. Windows Server appfabric physical architecture the Windows Server appfabric cache function uses a server cluster that communicates with each other to form a single unified application cache system. As a distributed cache system, all cache operations are abstracted as a single reference point, called a cache cluster. In other words, no matter how many computers constitute a cache cluster, your client applications can be used with the cache of a single logical unit in the cluster. The main components of the physical architecture include cache server, cache host Windows Service, cache cluster, Cache Management Tool Based on Windows powershell, cluster configuration storage location and cache client. Displays the association of all these elements.

 AppfabricCache service-> cache host-> cache cluster sAppfabric cache service is a Windows Service Running on one or more servers.Cache ServerEach server running the cache serviceA cache cluster is a collection of one or more instances of cache services that jointly store and distribute data in a ring manner.Windows Server appfabric cache logic architecture the logic architecture of the cache cluster in Windows Server appfabric consists of named cache, region, and cache object. In, the named cache spans all cache hosts in the cluster, but the region is limited to one cache host in the cluster.

The first is named cache, and the second is named cache, which can be divided into regions. The region is the container for storing data. The cached object can add tags to help index search. Named cache is also called cache. It is a configurable memory storage unit. All applications use this unit to store data in distributed cache. A region is an additional data container that can be placed in the cache. A region is a cache structure that is not defined in cluster configuration settings. Zones are optional. If you want to use them, you must use the application code Createregion Methods are explicitly created at runtime. Cache object uses itsSystem. ObjectThe form of the base class, so type conversion is required to restore them to their original type. When a tag is added to the cache, you can create additional tags for the object to facilitate retrieval. Overall comparison: memcahed is much more powerful than memcahed, but the configuration is much more complicated and MS-dependent. The cache management tool based on Windows powershell windows powershell is a dedicated management tool for the cache service. The Windows powershell Cache Management cmdlet can be installed on any domain computer or cache server. You can complete this operation by installing the appfabric cache management function. You must have administrator permissions on all cache servers to make the tool run properly. Use Windows powershell to start and stop clusters, add and delete named caches, change configuration settings, and view statistics of hosts and clusters. The local cache server uses serialization to store objects in the cache. When the cache client requests an object in the cache, the server sends the object to the client over the network. Then, the cache client deserializes the object for use by client applications. To accelerate the process of retrieving an object, enable local cache. When local caching is enabled, the cache client locally stores references to objects. This keeps the object active in the memory of the client application. When an application requests an object, the cache client first checks whether the object is in the local cache. If the object is in the local cache, the system immediately returns a reference to the object without contacting the server. If the object is not in the local cache, It is retrieved from the server. Then, the cache client deserializes the object and stores the reference of the newly retrieved object in the local cache. The client application also uses this object. The lifetime of an object in the local cache depends on multiple factors, such as the maximum number of objects in the local cache and the Failure policy. There are two types of local cache invalidation: timeout-based invalidation and notification-based invalidation. Locally cached objects are stored in the same process space of the cached client process. When the cache client requests a locally cached object, The client will receive a reference to the local cache object instead of a copy. For multi-threaded applications that may modify the same local cache object from multiple threads This is a very important note. These applications can use the standard. NET Framework encoding technology to synchronize object changes from multiple threads. You can also create a separate Datacachefactory Object. However, this operation should be performed with caution because the overhead of creating many cache factories may reduce the advantage. Expiration and eviction (Windows Server appfabric cache)

Cached objects are not permanently stored in the memory of Windows Server appfabric. Besides being explicitly deleted from the cache by using the remove method, the cached object may also expire or be evicted by the cache cluster.

Expired

Cache expiration allows the cache cluster to automatically delete cached objects from the cache. When usingPutOrAddYou can set an optional object timeout value for a specific cache object. This value determines the time when the object stays in the cache. If no timeout value is provided for the cached object, the lifetime of the object in the cache is determined using the value specified in the cluster configuration setting of the named cache.

When cache objects are locked for concurrent purposes, these objects will not be deleted from the cache even after their expiration time. Once these objects are unlocked, they are immediately deleted from the cache (if their expiration time expires ).
To prevent objects from being deleted immediately when they are unlocked,UnlockThe method also supports extending the cache object expiration time.

Local cache failure

 
For local cache, there are two complementary types of invalidation: timeout-based invalidation and notification-based invalidation.

Timeout-Based Failure

After downloading objects to the local cache, these objects will reside in the local cache until they reach the object timeout value specified in the cache client configuration settings. After the timeout value is reached, the object becomes invalid so that the next request can be refreshed from the cache cluster. Notification-Based Failure
If the cache client enables the local cache, you can also use the cache notification to automatically invalidate the locally cached objects. Shorten the lifetime of these objects as needed, which can reduce the possibility of applications using outdated data.

Eviction

To maintain the memory capacity available for caching on each cache host, appfabric supports least-recently-used (LRU) eviction. A threshold value is called a watermark to ensure that all cache hosts in the cluster are evenly distributed.

Configuration (the structure is similar to memcachedprovider and supports sessionstate) View code

 <? XML version  =  "  1.0  "  Encoding  =  "  UTF-8  "     ?>  
< Configuration >

<! -- Configsections must be the first element -->
< Configsections >
<! -- Required to read < Datacacheclient > Element -->
< Section name = " Datacacheclient "
Type = " Microsoft. applicationserver. caching. datacacheclientsection,
Microsoft. applicationserver. caching. Core, version = 1.0 . 0.0 ,
Culture = Neutral, publickeytoken = 31bf3856ad364e35 "
Allowlocation = " True "
Allowdefinition = " Everywhere " />
</ Configsections >

<! -- Cache Client -->
< Datacacheclient >
<! -- Cache host (s) -->
< Hosts >
< Host
Name = " Cacheserver1 "
Cacheport = " 22233 " />
</ Hosts >
</ Datacacheclient >

< System. Web >
< Sessionstate Mode = " Custom " Customprovider = " Appfabriccachesessionstoreprovider " >
< Providers >
<! -- Specify the named Cache For Session data -->
< Add
Name = " Appfabriccachesessionstoreprovider "
Type = " Microsoft. applicationserver. caching. datachesessionstoreprovider "
Cachename = " Namedcache1 "
Sharedid = " Sharedapp " />
</ Providers >
</ Sessionstate >
</ System. Web >
</ Configuration >
Sample Code View code

 //  Declare array for cache host (s ).  
Datacacheserverendpoint [] servers = New Datacacheserverendpoint [ 1 ];
Servers [ 0 ] = New Datacacheserverendpoint ( " Cacheserver2 " , 22233 );

// Setup the datachefactory configuration.
Datacachefactoryconfiguration factoryconfig = New Datacachefactoryconfiguration ();
Factoryconfig. Servers = Servers;

// Create a configured datacachefactory object.
Datachefactory mycachefactory = New Datacachefactory (factoryconfig );

// Get a cache client for the cache "namedcache1 ".
Datacache mydefaultcache = Mycachefactory. getcache ( " Namedcache1 " );

// Mydefaultcache. createregion ("area1 "); // Create Region
Generally, the Asp.net sesseion configuration is supported by default. The code and configuration files are simple, and the cache region and cache tag functions are extended to help you divide regions and differentiate data. In particular, the local cache function greatly improves the retrieval efficiency (for unchanged data), and also provides an expiration and eviction mechanism for local cache expiration. However, installation is troublesome. We recommend that you use web platform terraaller to install the patch and powershell to download the patch. Compared with memcached, memcached has powerful functions, but its configuration and expansion are not simple. In addition,. Net 4.0 supports cache extension. You can inherit objectcache to implement your own cache mechanism.

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.