Intro

Azure Cache for Redis provides an in-memory data store based on the Redis software. Redis improves the performance and scalability of an application that uses backend data stores heavily.


Documentation


Tips and Tidbits


Explore Azure Cache for Redis

Pattern

Description

Data cache

Databases are often too large to load directly into a cache. It's common to use the

cache-aside

pattern to load data into the cache only as needed. When the system makes changes to the data, the system can also update the cache, which is then distributed to other clients.

Content cache

Many web pages are generated from templates that use static content such as headers, footers, banners. These static items shouldn't change often. Using an in-memory cache provides quick access to static content compared to backend datastores.

Session store

This pattern is commonly used with shopping carts and other user history data that a web application might associate with user cookies. Storing too much in a cookie can have a negative effect on performance as the cookie size grows and is passed and validated with every request. A typical solution uses the cookie as a key to query the data in a database. Using an in-memory cache, like Azure Cache for Redis, to associate information with a user is much faster than interacting with a full relational database.

Job and message queuing

Applications often add tasks to a queue when the operations associated with the request take time to execute. Longer running operations are queued to be processed in sequence, often by another server. This method of deferring work is called task queuing.

Distributed transactions

Applications sometimes require a series of commands against a backend data-store to execute as a single atomic operation. All commands must succeed, or all must be rolled back to the initial state. Azure Cache for Redis supports executing a batch of commands as a single transaction.



Storing Web App Session State And HTTP Responses


Interact with Azure Cache for Redis by using .NET

using StackExchange.Redis;
...
var connectionString = "[cache-name].redis.cache.windows.net:6380,password=[password-here],ssl=True,abortConnect=False";
var redisConnection = ConnectionMultiplexer.Connect(connectionString);


Tutorial: Create a cache-aside leaderboard on ASP.NET

void ClearCachedTeams()
{
    IDatabase cache = Connection.GetDatabase();
    cache.KeyDelete("teamsList");
    cache.KeyDelete("teamsSortedSet");
    ViewBag.msg += "Team data removed from cache. ";
}