Share via


Develop for Azure In-Role Cache

Important

Microsoft recommends all new developments use Azure Redis Cache. For current documentation and guidance on choosing an Azure Cache offering, see Which Azure Cache offering is right for me?

Microsoft Azure Cache provides a set of APIs to add, update, and remove items from a cache. Using the classes and methods in the Microsoft.ApplicationServer.Caching namespace is a direct way of interacting with a Azure cache. Whereas, using one of the ASP.NET providers is an indirect way of using a Azure cache. The topics in this section cover direct programmatic use of caching. For more information about the ASP.NET providers for caching, see ASP.NET 4 Cache Providers for Azure In-Role Cache.

Programming Model

The caching programming model is designed for the cache-aside programming pattern. If your data is not present in the cache, your application, and not the distributed cache, must reload data into the cache from the original data source.

Cache-aside Programming Considerations

Design application code to function independent of the cache, so that the application continues to function if the cached data is not available. Because data in the cache is not persisted in a durable fashion, the possibility exists that the data in the case could be unavailable. For example, if the server that contains the data is restarted, the cached items in memory are lost. Requesting an item that does not exist in the cache is referred to as a cache miss.

When using the In-Role Cache high availability feature, backup copies of cached items help to guard against machine and process failures on a running cache cluster. But if all machines are restarted, then even high availability does not result in durability. Items that require persistence must use a database or other persistent-storage techniques. Caching then provides a mechanism for improving performance and scalability.

There are many other reasons that your code might encounter a cache miss. For example, the cache item might have expired or been evicted based on normal expiration and eviction policies. Regardless of the reason, the application code must be able to access the original data source to repopulate the item in the cache.

In This Section

See Also

Concepts

Using Azure In-Role Cache