- First, we import the following dependency to be able to use caching in ASP.NET Core applications:
"Microsoft.Extensions.Caching.Memory": "2.0.0"
- Next, we import the MVC dependency:
"Microsoft.AspNetCore.Mvc": "2.0.0"
- 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?}"); }); }
- Next, we create two folders at the project root, Controllers and Views.
- We then create HomeController.cs by right-clicking on the Controllers directory and selecting Add | New item | MVC Controller ...