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.Mvcdependency to the project:
"dependencies": {
"Microsoft.AspNetCore.Mvc": "2.0.0", - Next, we configure the ASP.NET routing in the
Configuremethod inStartup.cs:
public void Configure(IApplicationBuilder app)
{
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} - Now, we configure
Startup.csto create some cache profiles, adding some code in theConfigureServicesmethod:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options =>
{
options.CacheProfiles...