Eksportuj (0) Drukuj
Rozwiń wszystko
EN
Ta zawartość nie jest dostępna w wymaganym języku. Wersja w języku angielskim znajduje się tutaj.

Getting Started with Development for Azure In-Role Cache

Updated: February 16, 2015

noteNote
For guidance on choosing the right Azure Cache offering for your application, see Which Azure Cache offering is right for me?.

The topics in this section cover general development guidance for In-Role Cache.

There are a few basic steps to begin using caching in your application.

  1. Create a cache.

  2. Configure the clients to the cache.

  3. Use the caching API to use the cache.

In-Role Cache allows you to host caching within your Azure roles. One or more named caches can be created and use in your roles, and you only pay for the virtual machine instances required to meet your application and caching needs. This type of caching is enabled through the caching settings on the role properties in Visual Studio. For step-by-step instructions, see the following topics.

You must configure your application, also referred to as a cache client, to use the cache. This involves two steps:

  1. Reference the caching assemblies in your Visual Studio 2012 project.

  2. Use configuration file settings or code to configure access to the cache.

For more information on configuring your .NET project to use caching, see How to: Prepare Visual Studio to Use Azure In-Role Cache.

To configure access to a cache hosted on a Azure role, see How To Guide: Azure In-Role Cache.

The final step is to use the cache in your application code. This can be done in two ways:

  • Use the ASP.NET Providers for Session State and Output caching.

  • Use the Caching API to interact with the provisioned cache.

For more information on the ASP.NET providers, see ASP.NET 4 Cache Providers for Azure In-Role Cache.

To directly access to the cache in code, use the DataCache class in the In-Role Cache API. The following example demonstrates how to add and retrieve a string in the default cache using the settings from the default dataCacheClient section of the application configuration file.

// Cache client configured by settings in application configuration file.
DataCache defaultCache = new DataCache("default", "default");

// Put and retrieve a test object from the default cache.
defaultCache.Put("testkey", "testobject");
string strObject = (string)defaultCache.Get("testkey");

The previous example does not work in the RoleEntryPoint methods (WebRole.cs). For more information, see How to: Create a DataCache Object in RoleEntryPoint Methods in Azure In-Role Cache.

TipTip
For complete samples that demonstrate In-Role Cache hosted on Azure roles, see Azure In-Role Cache Samples.

See Also

Pokaż:
© 2015 Microsoft