|
1 |
| -# How to use the Async OutputCache Module |
2 |
| - 1. Target your application to 4.6.2+. |
3 |
| - |
4 |
| - The OutputCacheProviderAsync interface was introduced in .NET Framework 4.6.2, therefore you need to target your application to .NET Framework 4.6.2 or above in order to use the Async OutputCache Module. Download the [.NET Framework 4.6.2 Developer Pack](https://www.microsoft.com/en-us/download/details.aspx?id=53321) if you do not have it installed yet and update your application’s web.config targetFrameworks attributes as demonstrated below: |
5 |
| -```xml |
6 |
| -<system.web> |
7 |
| - <compilation debug="true" targetFramework="4.6.2"/> |
8 |
| - <httpRuntime targetFramework="4.6.2"/> |
9 |
| -</system.web> |
10 |
| -``` |
11 |
| - |
12 |
| - 2. Add the [Microsoft.AspNet.OutputCache.OutputCacheModuleAsync](https://www.nuget.org/packages/Microsoft.AspNet.OutputCache.OutputCacheModuleAsync/) NuGet package. |
13 |
| - |
14 |
| - Use the NuGet package manager to install the Microsoft.AspNet.OutputCache.OutputCacheModuleAsync package. This will add a reference to the Microsoft.AspNet.OutputCache.OutputCacheModuleAsync.dll and add the following configuration into the web.config file. |
15 |
| -```xml |
16 |
| -<system.webServer> |
17 |
| - <modules> |
18 |
| - <remove name="OutputCache"/> |
19 |
| - <add name="OutputCache" type="Microsoft.AspNet.OutputCache.OutputCacheModuleAsync, Microsoft.AspNet.OutputCache.OutputCacheModuleAsync" preCondition="integratedMode"/> |
20 |
| - </modules> |
21 |
| -</system.webServer> |
22 |
| -``` |
23 |
| - |
24 |
| -Now your applications will start using Async OutputCache Module. If no outputcacheprovider is specified in web.config, the module will use a default synchronous in-memory provider, with that you won’t get the async benefits. Please consider using one of the OutputCache providers that builds on this package, or [implement an async OutputCache Provider of your own](https://devblogs.microsoft.com/dotnet/introducing-the-asp-net-async-outputcache-module/#how-to-implement-an-async-outputcache-provider). |
| 1 | +# Microsoft.AspNet.OutputCache.OutputCacheModuleAsync |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +`OutputCacheModuleAsync` is an asynchronous implementation of ASP.NET's (4.X) output caching module. It provides performance improvements for web applications by caching the output of HTTP responses to reduce the need to execute the same request processing multiple times. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- Asynchronous caching operations for better scalability |
| 10 | +- Conditional request processing (If-Modified-Since, If-None-Match) |
| 11 | +- Customizable cache expiration policies |
| 12 | +- VaryBy parameter support (VaryByHeader, VaryByParam, VaryByCustom) |
| 13 | + |
| 14 | +## Integrations |
| 15 | + |
| 16 | +The `OutputCacheModuleAsync` is designed to work with any cache provider that implements the `OutputCacheProviderAsync` base class, allowing you to store cached content in various backends like SQL Server, Redis, or custom storage solutions. Two such providers are provided from the this same [repository](https://github.com/aspnet/AspNetOutputCache/): |
| 17 | + - [SQLAsyncOutputCacheProvider](https://www.nuget.org/packages/Microsoft.AspNet.OutputCache.SQLAsyncOutputCacheProvider/) |
| 18 | + - [CosmosDBTableAsyncOutputCacheProvider](https://www.nuget.org/packages/Microsoft.AspNet.OutputCache.CosmosDBTableAsyncOutputCacheProvider/) |
| 19 | + |
| 20 | +## Requirements |
| 21 | + |
| 22 | +- .NET Framework 4.6.2 or later (Full framework - not .NET Core) |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +1. **Target your application to .NET Framework 4.6.2 or later** |
| 27 | + |
| 28 | + The `OutputCacheProviderAsync` interface was introduced in .NET Framework 4.6.2, therefore you need to target your application to .NET Framework 4.6.2 or above in order to use the Async OutputCache Module. Download the [.NET Framework 4.6.2 Developer Pack](https://www.microsoft.com/en-us/download/details.aspx?id=53321) if you do not have it installed yet and update your application’s `web.config` targetFramework attributes as demonstrated below: |
| 29 | + |
| 30 | + ```xml |
| 31 | + <system.web> |
| 32 | + <compilation debug="true" targetFramework="4.6.2"/> |
| 33 | + <httpRuntime targetFramework="4.6.2"/> |
| 34 | + </system.web> |
| 35 | + ``` |
| 36 | + |
| 37 | +1. **Add the Microsoft.AspNet.OutputCache.OutputCacheModuleAsync NuGet package** |
| 38 | + |
| 39 | + Use the NuGet package manager to install the [Microsoft.AspNet.OutputCache.OutputCacheModuleAsync](https://www.nuget.org/packages/Microsoft.AspNet.OutputCache.OutputCacheModuleAsync/) package. This will add a reference to the `Microsoft.AspNet.OutputCache.OutputCacheModuleAsync.dll` and add the following configuration into the `web.config` file. |
| 40 | + |
| 41 | + ```xml |
| 42 | + <system.webServer> |
| 43 | + <modules> |
| 44 | + <remove name="OutputCache"/> |
| 45 | + <add name="OutputCache" type="Microsoft.AspNet.OutputCache.OutputCacheModuleAsync, Microsoft.AspNet.OutputCache.OutputCacheModuleAsync" preCondition="integratedMode"/> |
| 46 | + </modules> |
| 47 | + </system.webServer> |
| 48 | + ``` |
| 49 | + |
| 50 | +1. **Enable Output Caching in your application** |
| 51 | + |
| 52 | + Configure web forms applications for output caching by adding the following to the applications `web.config` file: |
| 53 | + |
| 54 | + ```xml |
| 55 | + <system.web> |
| 56 | + <caching> |
| 57 | + <outputCache enableOutputCache="true" /> |
| 58 | + <outputCacheSettings> |
| 59 | + <outputCacheProfiles> |
| 60 | + <add name="CacheFor60Seconds" duration="60" varyByParam="none" /> |
| 61 | + </outputCacheProfiles> |
| 62 | + </outputCacheSettings> |
| 63 | + </caching> |
| 64 | + </system.web> |
| 65 | + ``` |
| 66 | + |
| 67 | + You can also enable output caching in your MVC applications by adding the `OutputCache` attribute to your controllers or actions. For example: |
| 68 | + ```csharp |
| 69 | + [OutputCache(Duration = 60, VaryByParam = "none")] |
| 70 | + public ActionResult Index() |
| 71 | + { |
| 72 | + // This content will be cached for 60 seconds |
| 73 | + return View(); |
| 74 | + } |
| 75 | + ``` |
| 76 | + Now the applications will start using the Async OutputCache Module. |
| 77 | + |
| 78 | + If there are special requirements of a cache store that are not met by these released providers, consider [implementing an async OutputCache Provider of your own](https://devblogs.microsoft.com/dotnet/introducing-the-asp-net-async-outputcache-module/#how-to-implement-an-async-outputcache-provider). |
| 79 | + |
| 80 | +## Updates |
| 81 | + |
| 82 | +### v1.0.4 |
| 83 | + |
| 84 | + - Bug Fix: Fixed an issue with cache expiration policies not being applied correctly. |
| 85 | + |
| 86 | +### v1.0.1 |
| 87 | + |
| 88 | + - Added checks and support for kernel cache APIs in several places to ensure proper handling of kernel cache entries. Also updated the `DependencyRemovedCallback` method to invalidate kernel cache entries when dependencies change. |
| 89 | + - Added `[Serializable]` attributes to several classes to ensure they can be serialized correctly, which helps in caching scenarios. |
| 90 | + |
| 91 | +### v1.0.0 |
| 92 | + |
| 93 | + - Initial release. |
0 commit comments