diff --git a/aspnetcore/performance/caching/index.md b/aspnetcore/performance/caching/index.md index f39d4ef60c..22b49a8962 100644 --- a/aspnetcore/performance/caching/index.md +++ b/aspnetcore/performance/caching/index.md @@ -1,8 +1,8 @@ --- title: Caching | Microsoft Docs author: ardalis -description: -keywords: ASP.NET Core, +description: Demonstrates how to use caching for higher performance. +keywords: ASP.NET Core, caching, performance ms.author: riande manager: wpickett ms.date: 10/14/2016 @@ -15,7 +15,6 @@ uid: performance/caching/index # Caching * [In Memory Caching](memory.md) - * [Working with a Distributed Cache](distributed.md) - * [Response Caching](response.md) +* [Response caching middleware](middleware.md) diff --git a/aspnetcore/performance/caching/middleware.md b/aspnetcore/performance/caching/middleware.md new file mode 100644 index 0000000000..6427f0a57e --- /dev/null +++ b/aspnetcore/performance/caching/middleware.md @@ -0,0 +1,15 @@ +--- +title: 🔧 Response caching middleware +author: rick-anderson +ms.author: riande +manager: wpickett +ms.date: 10/14/2016 +ms.topic: article +ms.assetid: f9267eab-2762-42ac-1638-4a25d2c9d67c +ms.prod: aspnet-core +uid: performance/caching/middleware +--- +# 🔧 Response caching middleware + +> [!NOTE] +> We are currently working on this topic.We welcome your input to help shape the scope and approach. You can track the status and provide input on this [issue](https://github.com/aspnet/Docs/issues/2198) at GitHub.If you would like to review early drafts and outlines of this topic, please leave a note with your contact information in the [issue](https://github.com/aspnet/Docs/issues/2198). Learn more about how you can [contribute](https://github.com/aspnet/Docs/blob/master/CONTRIBUTING.md) on GitHub. diff --git a/aspnetcore/performance/caching/response.md b/aspnetcore/performance/caching/response.md index b0a0481c6d..68ffe508bf 100644 --- a/aspnetcore/performance/caching/response.md +++ b/aspnetcore/performance/caching/response.md @@ -1,92 +1,73 @@ --- title: Response Caching | Microsoft Docs -author: ardalis -description: +author: riande +description: Explains how to use Response caching to lower bandwidth and increase performance. keywords: ASP.NET Core, ms.author: riande +ms.author: riande manager: wpickett ms.date: 10/14/2016 ms.topic: article ms.assetid: cb42035a-60b0-472e-a614-cb79f443f654 -ms.technology: aspnet ms.prod: aspnet-core uid: performance/caching/response --- # Response Caching ->[!WARNING] -> This page documents version 1.0.0-rc1 and has not yet been updated for version 1.0.0 - -[Steve Smith](http://ardalis.com) +[Rick Anderson](https://twitter.com/RickAndMSFT) and [Steve Smith](http://ardalis.com) [View or download sample code](https://github.com/aspnet/Docs/tree/master/aspnetcore/performance/caching/response/sample) ## What is Response Caching -*Response caching* refers to specifying cache-related headers on HTTP responses made by ASP.NET Core MVC actions. These headers specify how you want client and intermediate (proxy) machines to cache responses to certain requests (if at all). This can reduce the number of requests a client or proxy makes to the web server, since future requests for the same action may be served from the client or proxy's cache. In this case, the request is never made to the web server. +*Response caching* adds cache-related headers to responses. These headers specify how you want client, intermediate (proxy) machines and middleware to cache responses. Response caching can reduce the number of requests a client or proxy makes to the web server. Response caching can also reduce the amount of work the web server performs to generate the response. Repeated matching may be served from the cache of the client, proxy or server. Cached responses can be returned by the client, the proxy or served by the response caching middleware. Cached requests served by the client or proxy save bandwidth and server load. Cached requests served by middleware can reduce web app server load. -![image](response/_static/proxy-and-cache.png) +The primary HTTP header used for caching is `Cache-Control`. See the [HTTP 1.1 Caching](https://tools.ietf.org/html/rfc7234#section-5.2) and [Cache-Control](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9) for more information. Common cache directives: -The primary HTTP header used for caching is `Cache-Control`. The [HTTP 1.1 specification](https://tools.ietf.org/html/rfc7234#section-5.2) details many options for this directive. Three common directives are: +* [public](https://tools.ietf.org/html/rfc7234#section-5.2.2.5) +* [private](https://tools.ietf.org/html/rfc7234#section-5.2.2.6) +* [no-cache](https://tools.ietf.org/html/rfc7234#section-5.2.1.4) +* [Pragma](https://tools.ietf.org/html/rfc7234#section-5.4) +* [Vary](https://tools.ietf.org/html/rfc7231#section-7.1.4) -**public** - - Indicates that the response may be cached. - -**private** - - Indicates the response is intended for a single user and **must not** be cached by a shared cache. The response could still be cached in a private cache (for instance, by the user's browser). - -**no-cache** - - Indicates the response **must not** be used by a cache to satisfy any subsequent request (without successful revalidation with the origin server). - -> [!NOTE] -> **Response caching does not cache responses on the web server**. It differs from [output caching](http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/improving-performance-with-output-caching-cs), which would cache responses in memory on the server in earlier versions of ASP.NET and ASP.NET MVC. Output caching middleware is planned to be added to ASP.NET Core in a future release. - -Additional HTTP headers used for caching include `Pragma` and `Vary`, which are described below. Learn more about [Caching in HTTP from the specification](https://tools.ietf.org/html/rfc7234#section-3). +Caching responses on the web server can be enabled by adding the [response caching middleware](https://github.com/aspnet/responsecaching). See [Response caching middleware](middleware.md) for more information. ## ResponseCache Attribute -The `ResponseCacheAttribute` is used to specify how a controller action's headers should be set to control its cache behavior. The attribute has the following properties, all of which are optional unless otherwise noted. +The [ResponseCacheAttribute](https://docs.microsoft.com/en-us/aspnet/core/api/microsoft.aspnetcore.mvc.responsecacheattribute) specifies the parameters necessary for setting appropriate headers in response caching. See [ResponseCacheAttribute](https://docs.microsoft.com/en-us/aspnet/core/api/microsoft.aspnetcore.mvc.responsecacheattribute) for a description of the parameters. -**Duration `int`** +`VaryByQueryKeys string[]`: When set, the response caching middleware will vary the stored response by the given list of query keys. The middleware will serve the stored response only if the query keys of the request matches those of the original request that generated the stored response. Setting this property without adding the middleware will throw a runttime exception. - The maximum duration (in seconds) the response should be cached. **Required** unless `NoStore` is `true`. + There is no corresponding HTTP header for this property. This property is an HTTP feature handled by the response caching middleware. To set the `VaryByQueryKeys` property, the response caching middleware must be enabled. -**Location `ResponseCacheLocation`** +The `ResponseCacheAttribute` is used to configure and create (via `IFilterFactory`) a `ResponseCacheFilter`. The `ResponseCacheFilter` performs the work of updating the appropriate HTTP headers and features of the response. The filter: - The location where the response may be cached. May be `Any`, `None`, or `Client`. Default is `Any`. +* Removes any existing headers for `Vary`, `Cache-Control`, and `Pragma`. +* Writes out the appropriate headers based on the properties set in the `ResponseCacheAttribute`. +* Updates the response caching HTTP feature if `VaryByQueryKeys` is set. -**NoStore `bool`** +### `Vary` - Determines whether the value should be stored or not, and overrides other property values. When `true`, `Duration` is ignored and `Location` is ignored for values other than `None`. +This header is only written when the `VaryByHeader` property is set. It is set to the `Vary` property's value. The following sample uses the `VaryByHeader` property. -**VaryByHeader `string`** +[!code-csharp[Main](response/sample/Controllers/HomeController.cs?name=snippet_VaryByHeader&highlight=1)] - When set, a `vary` response header will be written with the response. +You can view the response headers with your browsers network tools or the [Fidder tool](http://www.telerik.com/fiddler). The following image shows the Edge F12 output on the **Network** tab when the `About2` action method is called: -**CacheProfileName `string`** - - When set, determines the name of the cache profile to use. - -**Order `int`** - - The order of the filter (from `IOrderedFilter`). - -The `ResponseCacheAttribute` is used to configure and create (via `IFilterFactory`) a `ResponseCacheFilter`, which performs the work of writing the appropriate HTTP headers to the response. The filter will first remove any existing headers for `Vary`, `Cache-Control`, and `Pragma`, and then will write out the appropriate headers based on the properties set in the `ResponseCacheAttribute`. - -### The `Vary` Header - -This header is only written when the `VaryByHeader` property is set, in which case it is set to that property's value. +![Edge F12 output on the **Network** tab when the `About2` action method is called](response/_static/vary.png) ### `NoStore` and `Location.None` -`NoStore` is a special property that overrides most of the other properties. When this property is set to `true`, the `Cache-Control` header will be set to "no-store". Additionally, if `Location` is set to `None`, then `Cache-Control` will be set to "no-store, no-cache" and `Pragma` is likewise set to `no-cache`. (If `NoStore` is `false` and `Location` is `None`, then both `Cache-Control` and `Pragma` will be set to `no-cache`). +`NoStore` overrides most of the other properties. When this property is set to `true`, the `Cache-Control` header will be set to "no-store". If `Location` is set to `None`: -A good scenario in which to set `NoStore` to `true` is error pages. It's unlikely you would want to respond to a user's request with the error response a different user previously generated, and such responses may include stack traces and other sensitive information that shouldn't be stored on intermediate servers. For example: +* `Cache-Control` is set to `"no-store, no-cache"`. +* `Pragma` is set to `no-cache`. -[!code-csharp[Main](./response/sample/src/ResponseCacheSample/Controllers/HomeController.cs?highlight=1&range=30-34)] +If `NoStore` is `false` and `Location` is `None`, `Cache-Control` and `Pragma` will be set to `no-cache`. + +You typically set `NoStore` to `true` on error pages. For example: + +[!code-csharp[Main](response/sample/Controllers/HomeController.cs?name=snippet1&highlight=1)] This will result in the following headers: @@ -104,7 +85,7 @@ To enable caching, `Duration` must be set to a positive value and `Location` mus Below is an example showing the headers produced by setting `Duration` and leaving the default `Location` value. -[!code-csharp[Main](./response/sample/src/ResponseCacheSample/Controllers/HomeController.cs?highlight=1&range=22-28)] +[!code-csharp[Main](response/sample/Controllers/HomeController.cs?name=snippet_duration&highlight=1)] Produces the following headers: @@ -118,14 +99,13 @@ Instead of duplicating `ResponseCache` settings on many controller action attrib Setting up a cache profile: -[!code-csharp[Main](./response/sample/src/ResponseCacheSample/Startup.cs?highlight=5,6,7,8,9,10,11,12,13,14,15&range=12-28)] +[!code-csharp[Main](response/sample/Startup.cs?name=snippet1)] Referencing a cache profile: -[!code-csharp[Main](./response/sample/src/ResponseCacheSample/Controllers/HomeController.cs?highlight=1,4&range=5-12,35)] +[!code-csharp[Main](response/sample/Controllers/HomeController.cs?name=snippet_controller&highlight=1,4)] ->[!TIP] -> The `ResponseCache` attribute can be applied both to actions (methods) as well as controllers (classes). Method-level attributes will override the settings specified in class-level attributes. +The `ResponseCache` attribute can be applied both to actions (methods) as well as controllers (classes). Method-level attributes will override the settings specified in class-level attributes. In the above example, a class-level attribute specifies a duration of 30 seconds while a method-level attributes references a cache profile with a duration set to 60 seconds. @@ -134,3 +114,8 @@ The resulting header: ```javascript Cache-Control: public,max-age=60 ``` + + ### Additional Resources + +* [Caching in HTTP from the specification](https://tools.ietf.org/html/rfc7234#section-3) +* [Cache-Control](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9) \ No newline at end of file diff --git a/aspnetcore/performance/caching/response/_static/proxy-and-cache.png b/aspnetcore/performance/caching/response/_static/proxy-and-cache.png deleted file mode 100644 index ae338cfbe8..0000000000 Binary files a/aspnetcore/performance/caching/response/_static/proxy-and-cache.png and /dev/null differ diff --git a/aspnetcore/performance/caching/response/_static/vary.png b/aspnetcore/performance/caching/response/_static/vary.png new file mode 100644 index 0000000000..96353debee Binary files /dev/null and b/aspnetcore/performance/caching/response/_static/vary.png differ diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/.bowerrc b/aspnetcore/performance/caching/response/sample/.bowerrc similarity index 100% rename from aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/.bowerrc rename to aspnetcore/performance/caching/response/sample/.bowerrc diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Controllers/HomeController.cs b/aspnetcore/performance/caching/response/sample/Controllers/HomeController.cs similarity index 65% rename from aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Controllers/HomeController.cs rename to aspnetcore/performance/caching/response/sample/Controllers/HomeController.cs index 622061ccf3..50ce0fab4c 100644 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Controllers/HomeController.cs +++ b/aspnetcore/performance/caching/response/sample/Controllers/HomeController.cs @@ -2,6 +2,7 @@ namespace ResponseCacheSample.Controllers { + #region snippet_controller [ResponseCache(Duration = 30)] public class HomeController : Controller { @@ -10,7 +11,8 @@ namespace ResponseCacheSample.Controllers { return View(); } - + #endregion + #region snippet_about [ResponseCache(Duration = 10, Location = ResponseCacheLocation.Any, NoStore = false)] public IActionResult About() { @@ -18,7 +20,8 @@ namespace ResponseCacheSample.Controllers return View(); } - + #endregion + #region snippet_duration [ResponseCache(Duration = 60)] public IActionResult Contact() { @@ -26,11 +29,23 @@ namespace ResponseCacheSample.Controllers return View(); } - + #endregion + #region snippet1 [ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(); } + #endregion + #region snippet_VaryByHeader + [ResponseCache(VaryByHeader = "User-Agent", Duration = 30)] + public IActionResult About2() + { + #endregion + + ViewData["Message"] = "About2 VaryByHeader "; + + return View("About"); + } } } diff --git a/aspnetcore/performance/caching/response/sample/Program.cs b/aspnetcore/performance/caching/response/sample/Program.cs new file mode 100644 index 0000000000..2050f37267 --- /dev/null +++ b/aspnetcore/performance/caching/response/sample/Program.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; + +namespace ResponseCacheSample +{ + public class Program + { + public static void Main(string[] args) + { + var host = new WebHostBuilder() + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/aspnetcore/performance/caching/response/sample/ResponseCacheSample.sln b/aspnetcore/performance/caching/response/sample/ResponseCacheSample.sln deleted file mode 100644 index b74e8acf6c..0000000000 --- a/aspnetcore/performance/caching/response/sample/ResponseCacheSample.sln +++ /dev/null @@ -1,32 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{00B3B25C-17EF-4E95-8FF8-477BEE4DEAB1}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0DA9E497-2CFB-4366-9489-361D87F30D17}" - ProjectSection(SolutionItems) = preProject - global.json = global.json - EndProjectSection -EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ResponseCacheSample", "src\ResponseCacheSample\ResponseCacheSample.xproj", "{3EF40110-98B1-4B6E-8E06-AD21CD8DA869}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {3EF40110-98B1-4B6E-8E06-AD21CD8DA869}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3EF40110-98B1-4B6E-8E06-AD21CD8DA869}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3EF40110-98B1-4B6E-8E06-AD21CD8DA869}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3EF40110-98B1-4B6E-8E06-AD21CD8DA869}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {3EF40110-98B1-4B6E-8E06-AD21CD8DA869} = {00B3B25C-17EF-4E95-8FF8-477BEE4DEAB1} - EndGlobalSection -EndGlobal diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/ResponseCacheSample.xproj b/aspnetcore/performance/caching/response/sample/ResponseCacheSample.xproj similarity index 61% rename from aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/ResponseCacheSample.xproj rename to aspnetcore/performance/caching/response/sample/ResponseCacheSample.xproj index 0ef1e1c677..afe79df08a 100644 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/ResponseCacheSample.xproj +++ b/aspnetcore/performance/caching/response/sample/ResponseCacheSample.xproj @@ -4,12 +4,13 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + - 3ef40110-98b1-4b6e-8e06-ad21cd8da869 + ee294ce9-2562-4ef2-9b2a-28b1e823b904 ResponseCacheSample - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ + .\obj + .\bin\ + v4.5.2 2.0 @@ -17,7 +18,6 @@ - - + diff --git a/aspnetcore/performance/caching/response/sample/Startup.cs b/aspnetcore/performance/caching/response/sample/Startup.cs new file mode 100644 index 0000000000..8d36c6b0f9 --- /dev/null +++ b/aspnetcore/performance/caching/response/sample/Startup.cs @@ -0,0 +1,71 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.Mvc; + +namespace ResponseCacheSample +{ + public class Startup + { + public Startup(IHostingEnvironment env) + { + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) + .AddEnvironmentVariables(); + Configuration = builder.Build(); + } + + public IConfigurationRoot Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + #region snippet1 + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(options => + { + options.CacheProfiles.Add("Default", + new CacheProfile() + { + Duration = 60 + }); + options.CacheProfiles.Add("Never", + new CacheProfile() + { + Location = ResponseCacheLocation.None, + NoStore = true + }); + }); + } + #endregion + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(Configuration.GetSection("Logging")); + loggerFactory.AddDebug(); + + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseBrowserLink(); + } + else + { + app.UseExceptionHandler("/Home/Error"); + } + + app.UseStaticFiles(); + + app.UseMvc(routes => + { + routes.MapRoute( + name: "default", + template: "{controller=Home}/{action=Index}/{id?}"); + }); + } + } +} diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/Home/About.cshtml b/aspnetcore/performance/caching/response/sample/Views/Home/About.cshtml similarity index 100% rename from aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/Home/About.cshtml rename to aspnetcore/performance/caching/response/sample/Views/Home/About.cshtml diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/Home/Contact.cshtml b/aspnetcore/performance/caching/response/sample/Views/Home/Contact.cshtml similarity index 100% rename from aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/Home/Contact.cshtml rename to aspnetcore/performance/caching/response/sample/Views/Home/Contact.cshtml diff --git a/aspnetcore/performance/caching/response/sample/Views/Home/Index.cshtml b/aspnetcore/performance/caching/response/sample/Views/Home/Index.cshtml new file mode 100644 index 0000000000..288b16ed5d --- /dev/null +++ b/aspnetcore/performance/caching/response/sample/Views/Home/Index.cshtml @@ -0,0 +1,9 @@ +@{ + ViewData["Title"] = "Home Page"; +} + +

@ViewData["Title"].

+

@ViewData["Message"]

+ +

Index view.

+ diff --git a/aspnetcore/performance/caching/response/sample/Views/Shared/Error.cshtml b/aspnetcore/performance/caching/response/sample/Views/Shared/Error.cshtml new file mode 100644 index 0000000000..e514139c45 --- /dev/null +++ b/aspnetcore/performance/caching/response/sample/Views/Shared/Error.cshtml @@ -0,0 +1,14 @@ +@{ + ViewData["Title"] = "Error"; +} + +

Error.

+

An error occurred while processing your request.

+ +

Development Mode

+

+ Swapping to Development environment will display more detailed information about the error that occurred. +

+

+ Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. +

diff --git a/aspnetcore/performance/caching/response/sample/Views/Shared/_Layout.cshtml b/aspnetcore/performance/caching/response/sample/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000000..9717f7066e --- /dev/null +++ b/aspnetcore/performance/caching/response/sample/Views/Shared/_Layout.cshtml @@ -0,0 +1,67 @@ + + + + + + @ViewData["Title"] - ResponseCacheSample + + + + + + + + + + + + +
+ @RenderBody() +
+
+

© 2016 - ResponseCacheSample

+
+
+ + + + + + + + + + + + + @RenderSection("scripts", required: false) + + diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/_ViewImports.cshtml b/aspnetcore/performance/caching/response/sample/Views/_ViewImports.cshtml similarity index 69% rename from aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/_ViewImports.cshtml rename to aspnetcore/performance/caching/response/sample/Views/_ViewImports.cshtml index 7707f4b562..3ce1e63b2e 100644 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/_ViewImports.cshtml +++ b/aspnetcore/performance/caching/response/sample/Views/_ViewImports.cshtml @@ -1,3 +1,2 @@ @using ResponseCacheSample -@using Microsoft.Extensions.Options @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/_ViewStart.cshtml b/aspnetcore/performance/caching/response/sample/Views/_ViewStart.cshtml similarity index 100% rename from aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/_ViewStart.cshtml rename to aspnetcore/performance/caching/response/sample/Views/_ViewStart.cshtml diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/appsettings.json b/aspnetcore/performance/caching/response/sample/appsettings.json similarity index 61% rename from aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/appsettings.json rename to aspnetcore/performance/caching/response/sample/appsettings.json index 11efdbcbe8..fa8ce71a97 100644 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/appsettings.json +++ b/aspnetcore/performance/caching/response/sample/appsettings.json @@ -1,11 +1,8 @@ { - "ApplicationInsights": { - "InstrumentationKey": "" - }, "Logging": { "IncludeScopes": false, "LogLevel": { - "Default": "Verbose", + "Default": "Debug", "System": "Information", "Microsoft": "Information" } diff --git a/aspnetcore/performance/caching/response/sample/bower.json b/aspnetcore/performance/caching/response/sample/bower.json new file mode 100644 index 0000000000..69159b6667 --- /dev/null +++ b/aspnetcore/performance/caching/response/sample/bower.json @@ -0,0 +1,10 @@ +{ + "name": "asp.net", + "private": true, + "dependencies": { + "bootstrap": "3.3.6", + "jquery": "2.2.0", + "jquery-validation": "1.14.0", + "jquery-validation-unobtrusive": "3.2.6" + } +} diff --git a/aspnetcore/performance/caching/response/sample/bundleconfig.json b/aspnetcore/performance/caching/response/sample/bundleconfig.json new file mode 100644 index 0000000000..04754ba713 --- /dev/null +++ b/aspnetcore/performance/caching/response/sample/bundleconfig.json @@ -0,0 +1,24 @@ +// Configure bundling and minification for the project. +// More info at https://go.microsoft.com/fwlink/?LinkId=808241 +[ + { + "outputFileName": "wwwroot/css/site.min.css", + // An array of relative input file paths. Globbing patterns supported + "inputFiles": [ + "wwwroot/css/site.css" + ] + }, + { + "outputFileName": "wwwroot/js/site.min.js", + "inputFiles": [ + "wwwroot/js/site.js" + ], + // Optionally specify minification options + "minify": { + "enabled": true, + "renameLocals": true + }, + // Optinally generate .map file + "sourceMap": false + } +] diff --git a/aspnetcore/performance/caching/response/sample/global.json b/aspnetcore/performance/caching/response/sample/global.json deleted file mode 100644 index e793049cd5..0000000000 --- a/aspnetcore/performance/caching/response/sample/global.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "projects": [ "src", "test" ], - "sdk": { - "version": "1.0.0-preview2-003121" - } -} diff --git a/aspnetcore/performance/caching/response/sample/project.json b/aspnetcore/performance/caching/response/sample/project.json new file mode 100644 index 0000000000..8c6f140a03 --- /dev/null +++ b/aspnetcore/performance/caching/response/sample/project.json @@ -0,0 +1,65 @@ +{ + "dependencies": { + "Microsoft.NETCore.App": { + "version": "1.0.1", + "type": "platform" + }, + "Microsoft.AspNetCore.Diagnostics": "1.0.0", + "Microsoft.AspNetCore.Mvc": "1.0.1", + "Microsoft.AspNetCore.Razor.Tools": { + "version": "1.0.0-preview2-final", + "type": "build" + }, + "Microsoft.AspNetCore.Routing": "1.0.1", + "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", + "Microsoft.AspNetCore.StaticFiles": "1.0.0", + "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", + "Microsoft.Extensions.Configuration.Json": "1.0.0", + "Microsoft.Extensions.Logging": "1.0.0", + "Microsoft.Extensions.Logging.Console": "1.0.0", + "Microsoft.Extensions.Logging.Debug": "1.0.0", + "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", + "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0" + }, + + "tools": { + "BundlerMinifier.Core": "2.0.238", + "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", + "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" + }, + + "frameworks": { + "netcoreapp1.0": { + "imports": [ + "dotnet5.6", + "portable-net45+win8" + ] + } + }, + + "buildOptions": { + "emitEntryPoint": true, + "preserveCompilationContext": true + }, + + "runtimeOptions": { + "configProperties": { + "System.GC.Server": true + } + }, + + "publishOptions": { + "include": [ + "wwwroot", + "**/*.cshtml", + "appsettings.json", + "web.config" + ] + }, + + "scripts": { + "prepublish": [ "bower install", "dotnet bundle" ], + "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] + } +} diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Properties/launchSettings.json b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Properties/launchSettings.json deleted file mode 100644 index 92854c0cb1..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Properties/launchSettings.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:47943/", - "sslPort": 0 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "ResponseCacheSample": { - "commandName": "Project", - "launchBrowser": true, - "launchUrl": "http://localhost:5000", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} \ No newline at end of file diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Startup.cs b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Startup.cs deleted file mode 100644 index 5762f68ba1..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Startup.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.IO; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; - -namespace ResponseCacheSample -{ - public class Startup - { - // This method gets called by the web host. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services.AddMvc(options => - { - options.CacheProfiles.Add("Default", - new CacheProfile() - { - Duration=60 - }); - options.CacheProfiles.Add("Never", - new CacheProfile() - { - Location = ResponseCacheLocation.None, - NoStore = true - }); - }); - } - - // This method gets called by the web host. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app) - { - app.UseMvc(routes => - { - routes.MapRoute( - name: "default", - template: "{controller=Home}/{action=Index}/{id?}"); - }); - } - - // Entry point for the application. - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseKestrel() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() - .UseStartup() - .Build(); - - host.Run(); - } - } -} diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/Home/Index.cshtml b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/Home/Index.cshtml deleted file mode 100644 index 26e337fa5b..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/Home/Index.cshtml +++ /dev/null @@ -1,110 +0,0 @@ -@{ - ViewData["Title"] = "Home Page"; -} - - - - diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/Shared/Error.cshtml b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/Shared/Error.cshtml deleted file mode 100644 index 4852442680..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/Shared/Error.cshtml +++ /dev/null @@ -1,6 +0,0 @@ -@{ - ViewData["Title"] = "Error"; -} - -

Error.

-

An error occurred while processing your request.

diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/Shared/_Layout.cshtml b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/Shared/_Layout.cshtml deleted file mode 100644 index ea52730044..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/Views/Shared/_Layout.cshtml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - @ViewData["Title"] - ResponseCacheSample - - - - - - - - - - - - -
- @RenderBody() -
-
-

© 2016 - ResponseCacheSample

-
-
- - - - - - - - - - - - - @RenderSection("scripts", required: false) - - diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/bower.json b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/bower.json deleted file mode 100644 index ac5514caec..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/bower.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "ASP.NET", - "private": true, - "dependencies": { - "bootstrap": "3.3.5", - "jquery": "2.1.4", - "jquery-validation": "1.14.0", - "jquery-validation-unobtrusive": "3.2.4" - } -} diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/gulpfile.js b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/gulpfile.js deleted file mode 100644 index f79a1eb4f1..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/gulpfile.js +++ /dev/null @@ -1,45 +0,0 @@ -/// -"use strict"; - -var gulp = require("gulp"), - rimraf = require("rimraf"), - concat = require("gulp-concat"), - cssmin = require("gulp-cssmin"), - uglify = require("gulp-uglify"); - -var paths = { - webroot: "./wwwroot/" -}; - -paths.js = paths.webroot + "js/**/*.js"; -paths.minJs = paths.webroot + "js/**/*.min.js"; -paths.css = paths.webroot + "css/**/*.css"; -paths.minCss = paths.webroot + "css/**/*.min.css"; -paths.concatJsDest = paths.webroot + "js/site.min.js"; -paths.concatCssDest = paths.webroot + "css/site.min.css"; - -gulp.task("clean:js", function (cb) { - rimraf(paths.concatJsDest, cb); -}); - -gulp.task("clean:css", function (cb) { - rimraf(paths.concatCssDest, cb); -}); - -gulp.task("clean", ["clean:js", "clean:css"]); - -gulp.task("min:js", function () { - return gulp.src([paths.js, "!" + paths.minJs], { base: "." }) - .pipe(concat(paths.concatJsDest)) - .pipe(uglify()) - .pipe(gulp.dest(".")); -}); - -gulp.task("min:css", function () { - return gulp.src([paths.css, "!" + paths.minCss]) - .pipe(concat(paths.concatCssDest)) - .pipe(cssmin()) - .pipe(gulp.dest(".")); -}); - -gulp.task("min", ["min:js", "min:css"]); diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/package.json b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/package.json deleted file mode 100644 index d4d71a996e..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "ASP.NET", - "version": "0.0.0", - "devDependencies": { - "gulp": "3.8.11", - "gulp-concat": "2.5.2", - "gulp-cssmin": "0.1.7", - "gulp-uglify": "1.2.0", - "rimraf": "2.2.8" - } -} diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/project.json b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/project.json deleted file mode 100644 index 16f2fb8849..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/project.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "version": "1.0.0-*", - "buildOptions": { - "emitEntryPoint": true, - "preserveCompilationContext": true, - "copyToOutput": { - "include": [ - "wwwroot", - "web.config" - ] - } - }, - - "dependencies": { - "Microsoft.AspNetCore.Mvc": "1.0.0", - "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0" - }, - - "tools": { - "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" - }, - - "frameworks": { - "netcoreapp1.0": { - "dependencies": { - "Microsoft.NETCore.App": { - "version": "1.0.0", - "type": "platform" - } - } - } - }, - - "runtimeOptions": { - "configProperties": { - "System.GC.Server": true - } - }, - - "publishOptions": { - "include": [ - "wwwroot", - "web.config" - ] - }, - - "scripts": { - "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] - } -} diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/_references.js b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/_references.js deleted file mode 100644 index 9b2a79166f..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/_references.js +++ /dev/null @@ -1,7 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/css/site.css b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/css/site.css deleted file mode 100644 index 1eaae3d043..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/css/site.css +++ /dev/null @@ -1,34 +0,0 @@ -body { - padding-top: 50px; - padding-bottom: 20px; -} - -/* Wrapping element */ -/* Set some basic padding to keep content from hitting the edges */ -.body-content { - padding-left: 15px; - padding-right: 15px; -} - -/* Set widths on the form inputs since otherwise they're 100% wide */ -input, -select, -textarea { - max-width: 280px; -} - -/* Carousel */ -.carousel-caption { - z-index: 10 !important; -} - - .carousel-caption p { - font-size: 20px; - line-height: 1.4; - } - -@media (min-width: 768px) { - .carousel-caption { - z-index: 10 !important; - } -} diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/css/site.min.css b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/css/site.min.css deleted file mode 100644 index c12e1a1525..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/css/site.min.css +++ /dev/null @@ -1 +0,0 @@ -body{padding-top:50px;padding-bottom:20px}.body-content{padding-left:15px;padding-right:15px}input,select,textarea{max-width:280px}.carousel-caption{z-index:10!important}.carousel-caption p{font-size:20px;line-height:1.4}@media (min-width:768px){.carousel-caption{z-index:10!important}} \ No newline at end of file diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/favicon.ico b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/favicon.ico deleted file mode 100644 index a3a799985c..0000000000 Binary files a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/favicon.ico and /dev/null differ diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/images/ASP-NET-Banners-01.png b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/images/ASP-NET-Banners-01.png deleted file mode 100644 index ad3c267c7d..0000000000 Binary files a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/images/ASP-NET-Banners-01.png and /dev/null differ diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/images/ASP-NET-Banners-02.png b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/images/ASP-NET-Banners-02.png deleted file mode 100644 index 16c37fc55f..0000000000 Binary files a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/images/ASP-NET-Banners-02.png and /dev/null differ diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/images/Banner-01-Azure.png b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/images/Banner-01-Azure.png deleted file mode 100644 index 59fb923e05..0000000000 Binary files a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/images/Banner-01-Azure.png and /dev/null differ diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/images/Banner-02-VS.png b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/images/Banner-02-VS.png deleted file mode 100644 index c9f461137e..0000000000 Binary files a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/images/Banner-02-VS.png and /dev/null differ diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/js/site.js b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/js/site.js deleted file mode 100644 index 82ecce7b4a..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/js/site.js +++ /dev/null @@ -1 +0,0 @@ -// Write your Javascript code. diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/js/site.min.js b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/js/site.min.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/web.config b/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/web.config deleted file mode 100644 index 8485f6719f..0000000000 --- a/aspnetcore/performance/caching/response/sample/src/ResponseCacheSample/wwwroot/web.config +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/aspnetcore/performance/caching/response/sample/web.config b/aspnetcore/performance/caching/response/sample/web.config new file mode 100644 index 0000000000..dc0514fca5 --- /dev/null +++ b/aspnetcore/performance/caching/response/sample/web.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/aspnetcore/performance/caching/toc.md b/aspnetcore/performance/caching/toc.md index 2ebeb929f5..34a2ee49a3 100644 --- a/aspnetcore/performance/caching/toc.md +++ b/aspnetcore/performance/caching/toc.md @@ -1,3 +1,4 @@ # [In Memory Caching](memory.md) # [Working with a Distributed Cache](distributed.md) # [Response Caching](response.md) +# [Response caching middleware](middleware.md)