Windows Azure Caching: Difference between revisions

Content deleted Content added
Rothja (talk | contribs)
Creating a draft of a new page specifically for Windows Azure Caching, since it is no longer part of AppFabric where it is mentioned now. Once this is created the AppFabric and AppFabric Caching pages can be updated appropriately.
 
Rothja (talk | contribs)
Added code examples and the table at the end with related caching technologies.
Line 27:
 
A co-located cache is a cost-effective way to make use of existing memory on a role within a cloud service.
 
===Shared Caching===
Windows Azure Shared Caching provides caching as a managed service. The cache is provided as a multitenant service with usage quotas and is not a part of a cloud service deployment. The service is divided into tiers that range from 128 MB to 4 GB. In addition to storage capacity, each tier provides increasing processor and network capabilities. Shared Caching provides a way for multiple cloud services to access the same cache.
 
==Examples==
The following sections show Windows Azure Caching configuration and code examples.
 
===Configuration Example===
In Visual Studio, Caching on roles is configured in the Caching tab of the properties of the role that hosts Caching. TheThis followingmakes screenshotunderlying showschanges theseto the ServiceConfiguration.cscfg file. These settings indetermine Visualthe Studiotopology 2012used (dedicated or co-located) and the number of named caches and their settings.
 
Other roles must be configured to use Caching. One way to do this is with a [[NuGet]] package. This includes modifying the web.config to contain a properly configured dataCacheClients section. The following example dataCacheClients section specifies that the role that hosts Caching is named “CacheWorker1”.
 
<syntaxhighlight lang=XML>
<dataCacheClients>
<dataCacheClient name="default">
<autoDiscover isEnabled="true" identifier="CacheWorkerRole1" />
</dataCacheClient>
</dataCacheClients>
</syntaxhighlight>
 
===Code Example===
When hosting Caching on roles, the DataCache constructor can be used to specify both the named cache and the dataCacheClient section for the cache client settings. The following code shows these variations.
 
<syntaxhighlight lang=CSharp>
DataCache cache = new DataCache();
cache = new DataCache("default");
cache = new DataCache("NamedCache1", "default");
cache = new DataCache("NamedCache2", "customClient");
</syntaxhighlight>
 
The following method shows how 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 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.
 
<syntaxhighlight lang=CSharp>
function get_foo(int userid) {
/* first try the cache */
data = (dataType)cache.Get(userid) ;
if (!data) {
/* not found : request database */
data = db_select("SELECT * FROM users WHERE userid = ?", userid);
/* then store in cache until next get */
Cache.Add(userid, data);
}
return data;
}
</syntaxhighlight>
 
The following method shows how to update data already in the cache.
 
<syntaxhighlight lang=CSharp>
function update_foo(int userid, string dbUpdateString) {
/* first update database */
result = db_execute(dbUpdateString);
if (result) {
/* database update successful : fetch data to be stored in cache */
data = db_select("SELECT * FROM users WHERE userid = ?", userid);
/* the previous line could also look like data = createDataFromDBString(dbUpdateString); */
/* then store in cache until next get */
Cache.Put(userid, data);
}
}
</syntaxhighlight>
 
The following call removes the item from the cache.
 
<syntaxhighlight lang=CSharp>
Cache.Remove(userid);
</syntaxhighlight>
 
===Shared Caching===
Windows Azure Shared Caching provides caching as a managed service. TheUnlike co-located or dedicated topologies, the cache is providednot ashosted aon multitenantWindows serviceAzure withroles usagein quotasa andsingle iscloud notservice. aInstead, partthe ofcache is provided as a cloudmultitenant service deploymentwith usage quotas. The service is divided into tiers that range from 128 MB to 4 GB. In addition to storage capacity, each tier provides increasing processor and network capabilities. 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]]. Many of the assembly names, namespaces, and APIs are identical between the two products. The first release of Caching for Windows Azure in 2011 provided caching as a managed service in Windows Azure. This offering is now called Shared Caching.
 
In October 2012, support was added for hosting Caching on roles within a cloud service deployment. This is now called Window Azure Caching.
Line 55 ⟶ 103:
Windows Azure Caching is related to other Microsoft caching technologies. These technologies share similar features, such as the assembly name, namespace, and types. However, there are some differences. The table below describes these technologies.
 
{| class="wikitable"
|-
! Caching Technology !! Target !! Installed By !! Description
|-
| [[AppFabric_Caching_Service|AppFabric Caching]] || [[On-premises_software|On-Premises]] || [[AppFabric]] || Distributed on-premises cache that uses servers that the user provisions and manages.
|-
| Windows Azure Caching || [[Cloud_computing|Cloud]] || [http://www.windowsazure.com/en-us/develop/net/#/ Windows Azure SDK] || Caching is distributed across the instances of a single role in a Windows Azure cloud service deployment.
|-
| Windows Azure Caching || [[Cloud_computing|Cloud]] || [http://www.windowsazure.com/en-us/develop/net/#/ Windows Azure SDK] || Caching is provided through several tiers as a service for use by Windows Azure cloud applications.
|}
==References==
{{Reflist}}