Using ResponseCache attribute
In this recipe, we will learn how to use the ResponseCache
attribute in ASP.NET Core.
Getting ready
We will be using VS 2017, and will create a controller to manipulate the ResponseCache
attribute.
How to do it...
- First, we add the
Microsoft.AspNetCore.Mvc
dependency to the project:
"dependencies": { "Microsoft.AspNetCore.Mvc": "2.0.0",
- Next, we configure the ASP.NET routing in the
Configure
method inStartup.cs
:
public void Configure(IApplicationBuilder app) { app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
- Now, we configure
Startup.cs
to create some cache profiles, adding some code in theConfigureServices
method:
public void ConfigureServices(IServiceCollection services) { services.AddMvc(options => { options.CacheProfiles...