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
The response caching middleware enables the caching of server responses based on [HTTP Cache-Control headers](https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Cache-Control).
2
2
3
-
* Enables caching server responses based on [HTTP cache headers](https://developer.mozilla.org/docs/Web/HTTP/Headers/Cache-Control). Implements the standard HTTP caching semantics. Caches based on HTTP cache headers like proxies do.
4
-
* Is typically not beneficial for UI apps such as Razor Pages because browsers generally set request headers that prevent caching. [Output caching](xref:performance/caching/output), which is available in .NET 7 or later, benefits UI apps. With output caching, configuration decides what should be cached independently of HTTP headers.
5
-
* May be beneficial for public GET or HEAD API requests from clients where the [Conditions for caching](xref:performance/caching/middleware#cfc) are met.
3
+
* Caching behavior implements standard HTTP caching semantics.
6
4
7
-
To test response caching, use [Fiddler](https://www.telerik.com/fiddler), or another tool that can explicitly set request headers. Setting headers explicitly is preferred for testing caching. For more information, see [Troubleshooting](xref:performance/caching/middleware#troubleshooting).
5
+
* Caching is based on HTTP cache headers similar to the method used by proxies.
6
+
7
+
* This form of caching is useful for public GET or HEAD API requests from clients where the [conditions for caching](xref:performance/caching/middleware#cfc) are satisfied.
8
+
9
+
* For UI apps like Razor Pages, response caching isn't typically beneficial. Browsers commonly set request headers that prevent caching.
10
+
11
+
[Output caching](xref:performance/caching/output) (available in .NET 7 and later) is a better approach for UI apps. In this scenario, the configuration determines what to cache independent of HTTP headers.
12
+
13
+
To test response caching, use [Fiddler](https://www.telerik.com/fiddler) or another tool that can explicitly set request headers. Setting headers explicitly is preferred for testing caching. For more information, see [Response caching middleware > Troubleshooting](xref:performance/caching/middleware#troubleshooting).
Copy file name to clipboardExpand all lines: aspnetcore/performance/caching/hybrid/includes/overview.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
The <xref:Microsoft.Extensions.Caching.Hybrid.HybridCache> API bridges some gaps in the <xref:Microsoft.Extensions.Caching.Distributed.IDistributedCache> and <xref:Microsoft.Extensions.Caching.Memory.IMemoryCache> APIs. `HybridCache` is an abstract class with a default implementation that handles most aspects of saving to cache and retrieving from cache.
1
+
The <xref:Microsoft.Extensions.Caching.Hybrid.HybridCache> API bridges gaps in the <xref:Microsoft.Extensions.Caching.Distributed.IDistributedCache> and <xref:Microsoft.Extensions.Caching.Memory.IMemoryCache> APIs. `HybridCache` is an abstract class with a default implementation that handles most aspects of saving to cache and retrieving from cache.
2
2
3
-
### Features
3
+
### Features of HybridCache
4
4
5
-
`HybridCache`has the following features that the other APIs don't have:
5
+
`HybridCache`provides the following features that aren't available with other APIs:
6
6
7
7
* A unified API for both in-process and out-of-process caching.
8
8
@@ -11,13 +11,13 @@ simple API for adding new caching code. If the app has an `IDistributedCache` im
11
11
12
12
* Stampede protection.
13
13
14
-
*Cache stampede* happens when a frequently used cache entry is revoked, and too many requests try to repopulate the same cache entry at the same time. `HybridCache` combines concurrent operations, ensuring that all requests for a given response wait for the first request to populate the cache.
14
+
*Cache stampede* happens when a frequently used cache entry is revoked, and too many requests try to repopulate the same cache entry at the same time. `HybridCache` combines concurrent operations, which ensures that all requests for a given response wait for the first request to populate the cache.
15
15
16
16
* Configurable serialization.
17
17
18
-
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[]` internally, and uses `System.Text.Json` for everything else. It can be configured for other types of serializers, such as protobuf or XML.
18
+
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.
19
19
20
-
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:
20
+
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:
21
21
22
22
```csharp
23
23
publicclassSomeService(IDistributedCachecache)
@@ -52,9 +52,9 @@ public class SomeService(IDistributedCache cache)
52
52
}
53
53
```
54
54
55
-
That's a lot of work to get right each time, including things like serialization. And in the "cache miss" scenario, you could end up with multiple concurrent threads, all getting a cache miss, all fetching the underlying data, all serializing it, and all sending that data to the cache.
55
+
The code demonstrates a significant amount of work to get right each time, including things like serialization. Also in the "cache miss" scenario, you might end up with multiple concurrent threads. These threads might all receive a cache miss, all fetch the underlying data, all serialize it, and all send the data to the cache.
56
56
57
-
Here's equivalent code using `HybridCache`:
57
+
Here's equivalent code that uses the `HybridCache` API:
58
58
59
59
```csharp
60
60
publicclassSomeService(HybridCachecache)
@@ -71,16 +71,16 @@ public class SomeService(HybridCache cache)
71
71
}
72
72
```
73
73
74
-
The code is simpler and the library provides stampede protection and other features that `IDistributedCache`doesn't.
74
+
The code is simpler, and the library provides stampede protection and other features not available with the `IDistributedCache`interface.
75
75
76
76
### Compatibility
77
77
78
-
The `HybridCache` library supports older .NET runtimes, down to .NET Framework 4.7.2 and .NET Standard 2.0.
78
+
The `HybridCache` library supports older .NET runtimes, including .NET Framework 4.7.2 and .NET Standard 2.0.
79
79
80
-
### Additional resources
80
+
### More information
81
81
82
82
For more information, see the following resources:
83
83
84
-
*<xref:performance/caching/hybrid>
85
-
*[Hybrid Cache API proposal (`dotnet/aspnetcore`#54647)](https://github.com/dotnet/aspnetcore/issues/54647)
0 commit comments