You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-cache-for-redis/cache-aspnetcore-output-cache-provider.md
+37-39Lines changed: 37 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
-
title: ASP.NET core Output Cache Provider for Azure Cache for Redis
3
-
description: Use the Redis Output Cache Provider to cache ASP.NET core page output out of process with Azure Cache for Redis.
2
+
title: ASP.NET Core Output Cache Provider for Azure Cache for Redis
3
+
description: Learn how to use the Redis Output Cache Provider to cache ASP.NET Core page output out of process by using Azure Cache for Redis.
4
4
author: flang-msft
5
5
ms.author: cawa
6
6
ms.service: cache
@@ -9,69 +9,70 @@ ms.custom: devx-track-csharp
9
9
ms.topic: how-to
10
10
ms.date: 06/13/2024
11
11
12
-
13
-
#CustomerIntent: As a cloud developer, I want to understand core output caching using Azure Cache for Redis so that I can implement it for storing page output.
12
+
#customer intent: As a cloud developer, I want to understand core output caching via Azure Cache for Redis so that I can implement it for storing page output.
14
13
---
14
+
15
15
# ASP.NET Core Output Cache Provider for Azure Cache for Redis
16
16
17
-
This article explains how to configure Redis output caching middleware in an ASP.NET Core app. The output caching middleware enables caching of HTTP responses. The benefits for using output caching include:
17
+
This article explains how to configure Redis output caching middleware in an ASP.NET Core app. The output caching middleware enables caching of HTTP responses. The benefits of using output caching include:
18
18
19
-
- Saving web server resource utilization from repeatedly generating HTTP responses and rendering HTML web pages.
20
-
- Improving web request performance by reducing dependencies calls.
19
+
- Saving web server resource utilization from repeatedly generating HTTP responses and rendering HTML webpages.
20
+
- Improving web request performance by reducing dependency calls.
21
21
22
22
The benefits of using Azure Cache for Redis as your output cache include:
23
23
24
-
- Saving web server memory resource utilization by saving cached content in an external Redis.
25
-
- Improving web application resiliency by persisting cached content in an external Redis in the scenarios of server failover or restart.
26
-
- The Redis output caching implementation includes performance and storage optimizations comparing with custom implementations of the Output Caching middleware providers.
24
+
- Saving web server memory resource utilization by storing cached content in an external Redis database.
25
+
- Improving web application resiliency by persisting cached content in an external Redis database in the scenario of server failover or restart.
26
+
27
+
The Redis output caching implementation includes performance and storage optimizations that compare with custom implementations of the output caching middleware providers.
27
28
28
-
The output caching middleware can be used in all types of ASP.NET Core apps: Minimal API, Web API with controllers, MVC, and Razor Pages. For a detailed walkthrough on output caching syntax and features, see [Output caching middleware in ASP.NET Core](/aspnet/core/performance/caching/output).
29
+
You can use the output caching middleware in all types of ASP.NET Core apps: minimal API, web API with controllers, Model-View-Controller (MVC), and Razor Pages. For a detailed walkthrough of output caching syntax and features, see [Output caching middleware in ASP.NET Core](/aspnet/core/performance/caching/output).
29
30
30
31
## Prerequisites
31
32
32
-
-Install .NET 8 SDK or later. [Download](https://dotnet.microsoft.com/download/dotnet/8.0)
33
-
-Install Visual Studio Code. [Download](https://code.visualstudio.com/download)
34
-
- Create an Azure Cache for Redis instance.
33
+
-[Download](https://dotnet.microsoft.com/download/dotnet/8.0) and install .NET 8 SDK or later.
34
+
-[Download](https://code.visualstudio.com/download) and install Visual Studio Code.
35
+
- Create an Azure Cache for Redis instance. For more information, see:
35
36
-[Quickstart: Create an open-source Redis cache](./quickstart-create-redis.md)
36
37
-[Quickstart: Create a Redis Enterprise cache](./quickstart-create-redis-enterprise.md)
37
38
38
-
For an end-to-end application that uses Redis output caching, see [.NET 8 Web Application with Redis Output Caching and Azure OpenAI](https://github.com/Azure-Samples/azure-cache-redis-samples/tree/main/tutorial/output-cache-open-ai)
39
+
For an end-to-end application that uses Redis output caching, see [.NET 8 Web Application with Redis Output Caching and Azure OpenAI](https://github.com/Azure-Samples/azure-cache-redis-samples/tree/main/tutorial/output-cache-open-ai).
39
40
40
41
## Add Redis output caching middleware to an empty ASP.NET core web application
41
42
42
43
Here's the procedure for using Azure Cache for Redis as the output caching middleware in an ASP.NET Core app. The output caching middleware enables caching of HTTP responses as page output.
43
44
44
45
### Create an empty ASP.NET core web application
45
46
46
-
Open the command prompt. Use the .NET command line to create an empty ASP.NET core web application.
47
+
Open a command prompt. Use the .NET command line to create an empty ASP.NET core web application:
47
48
48
49
```cmd
49
50
mkdir RedisOutputCache
50
51
cd RedisOutputCache
51
52
dotnet new web
52
53
```
53
54
54
-
### Add Redis Output Caching NuGet Packages
55
+
### Add NuGet packages for Redis output caching
55
56
56
-
Make sure your command prompt is in the project folder where the `*.csproj` file is located. Install the [Microsoft.AspNetCore.OutputCaching.StackExchangeRedis](https://www.nuget.org/packages/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis) NuGet package.
57
+
Make sure your command prompt is in the project folder that contains the `*.csproj` file. Install the [Microsoft.AspNetCore.OutputCaching.StackExchangeRedis](https://www.nuget.org/packages/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis) NuGet package:
1. Save the _program.cs_ file. Make sure the application builds with no error in the Command Prompt.
117
+
1. Save the _Program.cs_ file. Make sure the application builds with no errors in the command prompt:
117
118
118
119
```cmd
119
120
dotnet build
120
121
```
121
122
122
-
### Configure Redis Cache connection
123
+
### Configure the Redis Cache connection
123
124
124
-
It's security best practice to not store password in clear text in source-controlled code files. ASP.NET core provides [User Secrets management](/aspnet/core/security/app-secrets) to ensure secrets, such as connection strings, are saved and accessed securely. Use this feature to manage the Azure Cache for Redis connection strings.
125
+
It's a security best practice to avoid storing passwords in clear text in source-controlled code files. ASP.NET Core provides [user secrets management](/aspnet/core/security/app-secrets) to help ensure that secrets, such as connection strings, are saved and accessed securely. Use this feature to manage the Azure Cache for Redis connection strings.
125
126
126
-
1. Enable secret storage using the CLI.
127
+
1. Enable the storage of secrets by using the Azure CLI:
127
128
128
129
```cli
129
130
dotnet user-secrets init
130
131
```
131
132
132
-
1. Obtain the Azure Cache for Redis connection strings using the Azure portal.
133
+
1. Obtain the Azure Cache for Redis connection strings by using the Azure portal.
133
134
134
-
The connection string for OSS Azure Cache for Redis can be found by selecting **Authentication** on the Resource menu.
You can find the connection string for Redis OSS by selecting **Authentication** on the **Resource** menu. Here's an example string: `<Azure_redis_name>.redis.cache.windows.net:6380,password=<Azure_redis_primary_accesskey>,ssl=True,abortConnect=False`.
136
136
137
-
The access keys for Enterprise Redis can found by selecting **Access keys** from the Resource menu. The connection string can be derived with other Redis information from the **Overview** section of the Resource menu.
You can find the access keys for Redis Enterprise by selecting **Access keys** on the **Resource** menu. The connection string can be derived with other Redis information from the **Overview** section of the **Resource** menu. Here's an example string: `<Azure_redis_name>.<Azure_region>.redisenterprise.cache.azure.net:10000,password=<Azure_redis_primary_accesskey>,ssl=True,abortConnect=False`.
139
138
140
-
1. Set the Redis connection for the web application using the CLI
139
+
1. Set the Redis connection for the web application by using the Azure CLI:
141
140
142
141
```cli
143
142
dotnet user-secrets set RedisCacheConnection <Azure_Redis_ConnectionString>
@@ -161,12 +160,11 @@ It's security best practice to not store password in clear text in source-contro
161
160
...
162
161
```
163
162
164
-
### Verify the Redis output cache is working
163
+
### Verify that the Redis output cache is working
165
164
166
-
1. Browse to the local host URL, for example:
167
-
`http://localhost:5063/cached`
165
+
1. Browse to the local host URL. Here's an example: `http://localhost:5063/cached`.
168
166
169
-
2. Observe if the current time is being displayed. Refreshing the browser doesn't change the time because the content is cached. The following example of text might be displayed by the /cached endpoint.
167
+
1. Observe if the current time is being displayed. Refreshing the browser doesn't change the time because the content is cached. The `/cached` endpoint might display text like the following example:
0 commit comments