Windows Azure Caching

From Wikipedia, the free encyclopedia

Windows Azure Caching was an in-memory, distributed caching feature designed for Microsoft Azure applications.[1] Caching was available as a part of the Windows Azure SDK. The Azure Managed Cache and In-Role Cache services were retired, and Microsoft recommended migration to .[2]

Architecture[]

Windows Azure Caching allows a cloud service to host Caching on a Windows Azure role.[1] The cache is distributed across all running instances of that role. Therefore, the amount of available memory in the cache is determined by the number of running instances of the role that hosts Caching and the amount of physical memory reserved for Caching on each instance.[3]

There are two deployment topologies for Caching:

Dedicated topology[]

In the dedicated topology, you define a worker role that is dedicated to Caching. This means that all of the worker role's available memory is used for the Caching and operating overhead.

The following diagram shows Caching in a dedicated topology. The cloud service shown has three roles: Web1, Worker1, and Cache1. There are two running instances of each role. In this example, the cache is distributed across all instances of the dedicated Cache1 role.

Represents a running Windows Azure cloud service that uses Caching with a dedicated topology.

A dedicated topology has the advantage of scaling the caching tier independently of any other role in the cloud service.[6] For the best Caching performance, a dedicated topology is recommended because the role instances do not share their resources with other application code and services.[4]

Co-located topology[]

In a co-located topology, you use a percentage of available memory on existing web or worker roles for Caching.[5]

The following diagram shows Caching in a co-located topology. The cloud service has two roles: Web1 and Worker1. There are two running instances of each role. In this example, the cache is distributed across all instances of the Web1 role. Because this role also hosts the web front-end for the cloud service, the cache is configured to use only a percentage of the physical memory on each instance of the Web1 role.

Represents a running Windows Azure cloud service that uses Caching with a co-located topology.

A co-located cache is a cost-effective way to make use of existing memory on a role within a cloud service.[5]

Examples[]

The following sections show Windows Azure Caching configuration and code examples.

Configuration example[]

In Visual Studio, Caching is configured in the Caching tab of the properties of the role that hosts Caching.[7] This makes underlying changes to the ServiceConfiguration.cscfg file.[8] These settings determine the topology used (dedicated or co-located) and the number of named caches[9] and their settings.

Other roles must be configured to use Caching.[10] One way to do this is with a NuGet package. This includes modifying the web.config to contain a properly configured dataCacheClients[11] section. The following example dataCacheClients section specifies that the role that hosts Caching is named “CacheWorker1”.

<dataCacheClients>
  <dataCacheClient name="default">
    <autoDiscover isEnabled="true" identifier="CacheWorkerRole1" />
  </dataCacheClient>
</dataCacheClients>

Code examples[]

Note that the code samples in this section are shown in C#.

When hosting Caching on roles, the DataCache class constructor can be used to specify both the named cache and the dataCacheClient section for the cache client settings. The following code shows how to create a named cache, NamedCache2, using the settings from a dataCacheClient section named customClient.

DataCache Cache = new DataCache("NamedCache2", "customClient");

The following method shows how to use the Cache object to retrieve data from the cache. In this example, a user identifier (userid) is the key for the associated user information object. The code first attempts to get this user information from the cache using the userid key. If that does not succeed, the code retrieves the information with a database query and then stores the returned user data in the cache. The next time the same code is run, the user information will be returned from the cache rather than the database. This assumes that the cached data has not been expired or evicted.

dataType GetUserData(string userid) 
{
    dataType data = null;

    // Attempt to retrieve the user data from the cache:
    object dataObject = Cache.Get(userid);

    if (dataObject != null)
       data = (dataType)dataObject;
    else
    {
       // If it doesn't exist in the cache, retrieve it from the database:
       data = GetUserDataFromDatabase("SELECT * FROM users WHERE userid = @userid", userid);

       // Put the returned data in the cache for future requests:
       Cache.Add(userid, data);
    }

    return data;
}

The following method shows how to update data that is already in the cache.

void UpdateUserData(string userid, dataType data) 
{
    // Update the user information in the database:
    result = UpdateUserDataInDatabase(userid, data);
    
    if (result) 
    {
       // If successfully updated, update the cache:
       Cache.Put(userid, data);
    }
}

The following call removes the item from the cache.

Cache.Remove(userid);

Shared Caching[]

Windows Azure Shared Caching provides caching as a managed service.[12] Unlike co-located or dedicated topologies, the cache is not hosted on Windows Azure roles in a single cloud service deployment. Instead, the cache is provided as a multitenant service with usage quotas.[13] The service is divided into tiers that range from 128 MB to 4 GB.[14] In addition to storage capacity, each tier provides increasing processor and network capabilities.[14] Shared Caching provides a way for multiple cloud services to access the same cache.

History[]

Windows Azure Caching has its roots in an on-premises technology, AppFabric. It was originally released as one of several Windows Azure AppFabric services, but the AppFabric designation in Windows Azure has since been abandoned. Many of the assembly names, namespaces, and APIs are identical between Windows Azure Caching and AppFabric Caching.[15] The first release of Caching for Windows Azure in April 2011 provided caching as a managed service in Windows Azure.[16] This offering is now called Shared Caching.

In October 2012, support was added for hosting Caching on roles within a cloud service deployment.[17] This is now called Windows Azure Caching.

Related caching technologies[]

Windows Azure Caching is related to other Microsoft caching technologies. These technologies share similar features, such as the assembly name, namespace, and types.[15] However, there are some differences. The table below describes these technologies.

Caching Technology Target Installed By Description
AppFabric Caching On-Premises AppFabric Distributed on-premises cache that uses servers that the user provisions and manages.
Windows Azure Caching Cloud Windows Azure SDK Caching is distributed across the instances of a single role in a Windows Azure cloud service deployment.
Windows Azure Shared Caching Cloud Windows Azure SDK Caching is provided as a multitenant service for use by Windows Azure cloud services.

References[]

  1. ^ a b "Caching in Windows Azure". MSDN Library. Microsoft. Retrieved 12 February 2013.
  2. ^ Rastogi, Pranav (3 December 2015). "Azure Managed Cache and In-Role Cache services to be retired on 11/30/2016". Microsoft Azure Blog. Retrieved 22 March 2017.
  3. ^ "Capacity Planning Considerations for Windows Azure Caching". MSDN Library. Microsoft. Retrieved 13 February 2013.
  4. ^ a b "Windows Azure Caching on Dedicated Roles". MSDN Library. Microsoft. Retrieved 13 February 2013.
  5. ^ a b c "Windows Azure Caching on Existing Roles". MSDN Library. Microsoft. Retrieved 13 February 2013.
  6. ^ "About Windows Azure Caching, Cache Cluster". MSDN Library. Microsoft. Retrieved 13 February 2013.
  7. ^ "How to Use Windows Azure Caching". Windows Azure Website. Microsoft. Retrieved 13 February 2013.
  8. ^ "Windows Azure Caching Role Configuration Settings (ServiceConfiguration.cscfg)". MSDN Library. Microsoft. Retrieved 13 February 2013.
  9. ^ "About Windows Azure Caching, Named Caches". MSDN Library. Microsoft. Retrieved 13 February 2013.
  10. ^ "Getting Started with Development for Windows Azure Caching, Configure the Clients". MSDN Library. Microsoft. Retrieved 13 February 2013.
  11. ^ "Windows Azure Caching Client Configuration Settings (Web.config), dataCacheClients". MSDN Library. Microsoft. Retrieved 13 February 2013.
  12. ^ "About Windows Azure Shared Caching". MSDN Library. Microsoft. Retrieved 13 February 2013.
  13. ^ "Understanding Quotas for Windows Azure Shared Caching". MSDN Library. Microsoft. Retrieved 13 February 2013.
  14. ^ a b "Windows Azure Shared Caching FAQ". MSDN Library. Microsoft. Retrieved 13 February 2013.
  15. ^ a b "Differences Between Caching On-Premises and in the Cloud". MSDN Library. Microsoft. Retrieved 13 February 2013.
  16. ^ "Introducing the Windows Azure Caching Service". MSDN Magazine. Microsoft. Retrieved 13 February 2013.
  17. ^ "Windows Azure Caching Release Notes (October 2012)". MSDN Library. Microsoft. Retrieved 13 February 2013.

External links[]

Retrieved from ""