How to do it...

  1. First, we import the following dependency to be able to use caching in ASP.NET Core applications:
"Microsoft.Extensions.Caching.Memory": "2.0.0"  
  1. Next, we import the MVC dependency:
"Microsoft.AspNetCore.Mvc": "2.0.0"  
  1. We can now add the cache middleware:
public void ConfigureServices(IServiceCollection services) 
{ 
    services.AddMemoryCache(); 
    services.AddMvc(); } 
public void Configure(IApplicationBuilder app) 
{ 
    app.UseMvc(routes => 
    { 
        routes.MapRoute( 
        name: "default", 
        template: "{controller=Home}/{action=Index}/{id?}"); 
    }); 
} 
  1. Next, we create two folders at the project root, Controllers and Views.
  2. We then create HomeController.cs by right-clicking on the Controllers directory and selecting Add | New item | MVC Controller ...

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.