The cloud service Base application is also known as the "csfundahttp://www.aliyun.com/zixun/aggregation/29845.html" >mentals, which shows how to build Azure services supported by the database. In the Dal–rdbms section of the previous blog post, we discussed a technique for implementing lateral scalability in the database layer, i.e. partitioning. In this article, we will discuss the importance of caching, the factors to consider, and how to configure and implement it in Windows Azure.
The distributed caching architecture is built on a scale-out basis, where several computers (physical machines or virtual machines) will be part of a cluster ring that has the inherent partitioning capability to apportion the workload. Cached as <key, value> lookup paradigm, their values are serialized objects, which may be the result set of a more complex data storage operation, such as performing a JOIN operation across multiple tables in a database. Therefore, using caching, you do not have to perform operations on the data store more than once, but fast key lookups for caching.
Understand what is appropriate for caching
First, you need to analyze the workload and determine the appropriate cache object. When data is cached, "expired" fault tolerance between the cache and the data source should be within the acceptable scope of the application. In general, caching can be used as a reference (for all users are read-only), such as user profiles, user sessions (read-write by a single user), or, in some cases, as resource data (using the lock API to allow all users to read and write). In some cases, a particular dataset might not be appropriate for caching-for example, if a particular dataset is changing rapidly, the application cannot tolerate expiration, or you need to execute something.
Capacity Planning
The next step is to estimate the application's caching requirements. This requires looking at a range of metrics, just above the cache size, to make the initial size guide.
Cache Size: You can use the average size of objects and the number of objects to approximate the amount of memory required. Access mode and throughput requirements: The read-write combination shows the creation of new objects, the re-writing of existing objects, or the reading of objects. Policy settings: Lifetime (TTL), high Availability (HA), expiration type, and eviction policy settings. Physical resources: In addition to memory, network bandwidth and CPU utilization are also important. Network broadband can be estimated based on specific inputs, but in most cases, network broadband should be monitored and used as a basis for recalculation.
More detailed capacity planning spreadsheets can be obtained from http://msdn.microsoft.com/en-us/library/hh914129
Azure Cache topology
The following table lists the PAAS option sets provided on Azure and provides a brief description
Type
Description
In-role Dedicated
In a private topology, you can define a caching-specific worker role. This means that all available memory for worker role can be used for caching and running overhead.
Http://msdn.microsoft.com/en-us/library/windowsazure/hh914140.aspx
In-role co-located
In the co-located topology, you can cache using a certain percentage of the available memory on the application role. For example, you can allocate 20% of physical memory for caching on each instance of a Web role.
Http://msdn.microsoft.com/en-us/library/windowsazure/hh914128.aspx
Windows Azure Caching Service
The Windows Azure Cache service is currently in the preview state (September 2013). Here are some useful links
Http://blogs.msdn.com/b/azchina/archive/2013/09/03/announcing-new-windows-azure-cache-preview.aspx
Http://msdn.microsoft.com/en-us/library/windowsazure/dn386094.aspx
Windows Azure Shared Cache
The multi-tenant cache (with restrictions and quotas) will be deactivated by September 2014 at the latest. More detailed information can be obtained from http://www.windowsazure.com/en-us/pricing/details/cache/. It is recommended that the customer use one of the above options to take advantage of the cache.
Implementation Details
The Csfundamentals application uses the Azure cache of In-role dedicated to simplify reading frequently accessed information, such as user profile information, user annotations. In-role dedicated deployment is preferred because it separates cache-related workloads. It can then be monitored through performance counters (CPU usage, network bandwidth, memory, and so on) and corresponding scalable cache role instances.
Note: The new Windows Azure cache service is not available during the implementation of Csfundamentals. In addition to csfundamentals applications, this is preferred if you need to use cached data.
The Icachefactory interface defines the GetCache method signature. The Icacheclient interface defines the get<t> and put<t> method signatures.
public interface Icacheclient
Azurecacheclient implements this interface and references Windows Azure cache client assemblies that are added through the Windows Azure Caching NuGet package.
Creating a Datacachefactory object creates an expensive connection to a cached role instance, so it is defined as a static connection and is instantiated using lazy<t> slowly.
App.config is enabled for automatic discovery and identifiers are used to correctly point to caching worker role:
<autodiscover isenabled= "true" identifier= "Csfundamentalscaching.workerrole"/>
Note: To modify the solution to use the new Windows Azure Caching service, replace the identifier attribute with the cache service endpoint created in the Windows Azure Portal. Additionally, the API key, which can be retrieved from the Manage Keys option on the portal, must be copied to the Messagesecurity authorizationinfo field in app.config.
The implementation of the get<t> and Put<t> methods uses the Binaryserializer class, and the Binaryserializer class uses the Protobuf class to serialize and deserialize. Protobuf-net is a. NET implementation of Kyoto buffers, which enables you to serialize. NET objects efficiently and easily. Added by Protobuf-net NuGet package.
Serialize to the incoming parameter T to generate the byte] array and store it in the Windows Azure cache cluster. In order to return the object for a particular key request, the Get method uses a deserialization method.
This blog outlines the basics of caching. For more information, see ICacheClient.cs, AzureCacheFactory.cs, AzureCacheClient.cs, and cloudservicefundamentals Visual Studio Solutions BinarySerializer.cs.