From 641792b2e3a32ce502db495238512c1381c5d6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Sat, 21 Dec 2019 19:43:19 +0100 Subject: [PATCH] Implemented Response Cashing --- H_PLUS_Sports/Controllers/CustomersController.cs | 2 ++ H_PLUS_Sports/Startup.cs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/H_PLUS_Sports/Controllers/CustomersController.cs b/H_PLUS_Sports/Controllers/CustomersController.cs index b8b9148..ebf164f 100644 --- a/H_PLUS_Sports/Controllers/CustomersController.cs +++ b/H_PLUS_Sports/Controllers/CustomersController.cs @@ -26,6 +26,7 @@ namespace HPlusSportsAPI.Controllers [HttpGet] [Produces(typeof(DbSet))] + [ResponseCache(Duration = 60)] public IActionResult GetCustomer() { var results = new ObjectResult(_customerRepository.GetAll()) @@ -40,6 +41,7 @@ namespace HPlusSportsAPI.Controllers [HttpGet("{id}")] [Produces(typeof(Customer))] + [ResponseCache(Duration = 60)] public async Task GetCustomer([FromRoute] int id) { if (!ModelState.IsValid) diff --git a/H_PLUS_Sports/Startup.cs b/H_PLUS_Sports/Startup.cs index 67ea22b..4a2c56c 100644 --- a/H_PLUS_Sports/Startup.cs +++ b/H_PLUS_Sports/Startup.cs @@ -36,6 +36,8 @@ namespace H_Plus_Sports services.AddScoped(); services.AddScoped(); + services.AddResponseCaching(); + services.AddMvc(option => option.EnableEndpointRouting = false) .SetCompatibilityVersion(CompatibilityVersion.Version_3_0) .AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore); @@ -53,6 +55,8 @@ namespace H_Plus_Sports app.UseDeveloperExceptionPage(); } + app.UseResponseCaching(); + app.UseHttpsRedirection(); app.UseRouting();