Light Freshness Edit: ASP.NET - Caching#37087
Light Freshness Edit: ASP.NET - Caching#37087GitHubber17 wants to merge 4 commits intodotnet:mainfrom
Conversation
|
@tdykstra - Refreshed topics for your review. See the top comment for details. |
wadepickett
left a comment
There was a problem hiding this comment.
Reviewed. Great work! A few minor items suggested.
I will wait for @tdykstra to review before this is merged since he owns these topics.
| The output caching middleware can be used in all types of ASP.NET Core apps: [Minimal APIs](xref:fundamentals/minimal-apis), [Web API with controllers](xref:web-api/index), [MVC](xref:mvc/overview), and [Razor Pages](xref:razor-pages/index). Code examples are provided for Minimal APIs and controller-based APIs. The controller-based API examples show how to use attributes to configure caching. These attributes can also be used in MVC and Razor Pages apps. | ||
|
|
||
| The code examples refer to a [Gravatar class](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/performance/caching/output/samples/7.x/Gravatar.cs) that generates an image and provides a "generated at" date and time. The class is defined and used only in [the sample app](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/performance/caching/output/samples/7.x). Its purpose is to make it easy to see when cached output is being used. For more information, see [How to download a sample](xref:fundamentals/index#how-to-download-a-sample) and [Preprocessor directives in sample code](xref:index#preprocessor-directives-in-sample-code). | ||
| The code examples refer to a [Gravatar class](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/performance/caching/output/samples/7.x/Gravatar.cs) that generates an image and provides a "generated at" date and time. The class is defined and used only in [the sample app](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/performance/caching/output/samples/7.x). Its purpose is to make it easy to see when cached output is being used. For more information, see [How to download a sample](xref:fundamentals/index#how-to-download-a-sample) and [Preprocessor directives](/dotnet/csharp/fundamentals/program-structure/preprocessor-directives). |
There was a problem hiding this comment.
@wadepickett - The <xref:index#preprocessor-directives-in-sample-code> link redirects to the top of the Overview page, which provides no information about preprocessor directives. I tried to find a replacement. Can you identify a more appropriate link?
Co-authored-by: Wade Pickett <wpickett@microsoft.com>
|
I deleted my suggestion for the link change for preprocessor-directives, but that also deleted the conversation history. So I'll note it here: The link I suggested resolved to the top of the overview page which made it useless. At some point we deleted that section in the overview. Sorry to mess that up. You aleady had the best link we can provide. Follow up for me: I will also look through the entire repo to see if that original outdated link is anywhere else and get it fixed. Thanks for finding this issue to begin with! |
wadepickett
left a comment
There was a problem hiding this comment.
Approved. Great work, thanks!
@tdykstra will also provide a review and then merge.
tdykstra
left a comment
There was a problem hiding this comment.
Looks good.
One important update -- there's a new Azure Redis service
| Serialization is configured as part of registering the service, with support for type-specific and generalized serializers via the `WithSerializer` and `WithSerializerFactory` methods, chained from the `AddHybridCache` call. By default, the service handles `string` and `byte[]` types internally, and uses the `System.Text.Json` namespace for everything else. `HybridCache` can be configured for other types of serializers, such as protobuf or XML. | ||
|
|
||
| To see the relative simplicity of the `HybridCache` API, compare code that uses it to code that uses `IDistributedCache`. Here's an example of what using `IDistributedCache` looks like: | ||
| To see the relative simplicity of the `HybridCache` API, compare code that uses it to code that uses the `IDistributedCache` interface. Here's an example of a configuration with the `IDistributedCache` interface: |
There was a problem hiding this comment.
Please revert line 20 to the original text.
| * <xref:performance/caching/hybrid> | ||
| * [Hybrid Cache API proposal (`dotnet/aspnetcore` #54647)](https://github.com/dotnet/aspnetcore/issues/54647) | ||
| * [`HybridCache` source code](https://source.dot.net/#Microsoft.Extensions.Caching.Abstractions/Hybrid/HybridCache.cs,8c0fe94693d1ac8d) <!--keep--> | ||
| * [HybridCache library in ASP.NET Core](xref:performance/caching/hybrid) |
There was a problem hiding this comment.
The original form of link here is fine. It gets the link text from the title of the article.
| An app configures the cache implementation with a <xref:Microsoft.Extensions.Caching.StackExchangeRedis.RedisCache> instance by calling the <xref:Microsoft.Extensions.DependencyInjection.StackExchangeRedisCacheServiceCollectionExtensions.AddStackExchangeRedisCache%2A> method. For [output caching](xref:performance/caching/output#cache-storage), use the <xref:Microsoft.Extensions.DependencyInjection.StackExchangeRedisOutputCacheServiceCollectionExtensions.AddStackExchangeRedisOutputCache%2A> method. | ||
|
|
||
| We recommend production apps use the Distributed Redis Cache because it's the most performant. For more information see [Recommendations](#recommendations). | ||
| 1. Create an Azure Cache for Redis. |
There was a problem hiding this comment.
| 1. Create an Azure Cache for Redis. | |
| 1. Create an instance of Azure Cache for Redis. |
| 1. Create an Azure Cache for Redis. | ||
|
|
||
| [Redis](https://redis.io/) is an open source in-memory data store, which is often used as a distributed cache. You can configure an [Azure Cache for Redis](/azure/azure-cache-for-redis/cache-overview) for an Azure-hosted ASP.NET Core app, and use an Azure Cache for Redis for local development. | ||
| 1. Copy the Primary connection string (StackExchange.Redis) to [Configuration](xref:fundamentals/configuration/index). |
There was a problem hiding this comment.
| 1. Copy the Primary connection string (StackExchange.Redis) to [Configuration](xref:fundamentals/configuration/index). | |
| 1. Copy the primary connection string (StackExchange.Redis) to [Configuration](xref:fundamentals/configuration/index). |
| * Azure: Save the connection string in a secure store such as [Azure Key Vault](/azure/key-vault/general/overview) | ||
| - **For Azure**: Save the connection string in a secure store such as [Azure Key Vault](/azure/key-vault/general/overview). | ||
|
|
||
| The following code enables the Azure Cache for Redis: |
There was a problem hiding this comment.
change Azure Cache for Redis to Azure Managed Redis and link to
the Azure Managed Redis overview page
Azure Cache for Redis is retiring
| When the sample app starts, the <xref:Microsoft.Extensions.Caching.Distributed.IDistributedCache> instance is injected into the _Program.cs_ file. The current time is cached by using the <xref:Microsoft.Extensions.Hosting.IHostApplicationLifetime> interface. (For more information, see [.NET Generic Host: IHostApplicationLifetime](xref:fundamentals/host/generic-host#ihostapplicationlifetime).) | ||
|
|
||
| [!code-csharp[](~/performance/caching/distributed/samples/6.x/DistCacheSample/Program.cs?name=snippet_Configure)] | ||
|
|
||
| The sample app injects <xref:Microsoft.Extensions.Caching.Distributed.IDistributedCache> into the `IndexModel` for use by the Index page. | ||
| The sample app injects the <xref:Microsoft.Extensions.Caching.Distributed.IDistributedCache> instance into the `IndexModel` object for use by the Index page. |
There was a problem hiding this comment.
Good catch here and throughout these docs, adding instance and object, etc. where appropriate instead of the API reference by itself.
| * [Cache in-memory in ASP.NET Core](xref:performance/caching/memory) | ||
| * [Detect changes with change tokens in ASP.NET Core](xref:fundamentals/change-tokens) | ||
| * [Response caching in ASP.NET Core](xref:performance/caching/response) | ||
| * [Response caching middleware in ASP.NET Core](xref:performance/caching/middleware) | ||
| * [Host ASP.NET Core in a web farm](xref:host-and-deploy/web-farm) |
There was a problem hiding this comment.
Quite a few links were removed. I would like to keep the ones that people might otherwise not think of looking for and drop those that are nearby in the TOC.
| The [RFC 9111: HTTP Caching (Section 5.2. Cache-Control)](https://www.rfc-editor.org/rfc/rfc9111#field.cache-control) specification requires a cache to honor a valid `Cache-Control` header sent by the client. A client can make requests with a `no-cache` header value and force the server to generate a new response for every request. | ||
|
|
||
| Always honoring client `Cache-Control` request headers makes sense if you consider the goal of HTTP caching. Under the official specification, caching is meant to reduce the latency and network overhead of satisfying requests across a network of clients, proxies, and servers. It isn't necessarily a way to control the load on an origin server. | ||
| Always honoring client `Cache-Control` request headers makes sense if you consider the goal of HTTP caching. Under the official specification, caching is meant to reduce the latency and network overhead of satisfying requests across a network of clients, proxies, and servers. The approach isn't necessarily a way to control the load on an origin server. |
There was a problem hiding this comment.
"It" here most likely refers back to "caching" in "caching is meant to reduce..."
"The approach" doesn't fit as well with what comes before or what comes after.
The requested change would have taken us out of the scope of light freshness edit. we will save the Redis change for another issue.
tdykstra
left a comment
There was a problem hiding this comment.
Approved, will merge when comments are addressed., except ignore the Redis service change.
|
@tdykstra - Thank you for your review. I applied your requested changes and held off on changes related to comments about changing the Azure Redis service. |
This PR contains light freshness updates to five articles:
For details, see ADO request 568764.
Internal previews