Azure Cache In ASP.NET Core 2.0

In this article, we will learn how to use Azure Redis cache in ASP.NET Core.

Solution

Create a class library and add the following NuGet packages.

  • StackExchange.Redis
  • Newtonsoft.json

Add a class to encapsulate the settings.

Add a class for cache storage. Add a constructor and private methods to initialize the Azure client.

Now, add methods to access the cache.

Inject and use the class.

In ASP.NET Core web application, configure the services.

Discussion

The sample code will require you to setup Azure account and Redis cache. Instructions for these can be found here.

Source Code

GitHub