Implemented Response Cashing
This commit is contained in:
@ -26,6 +26,7 @@ namespace HPlusSportsAPI.Controllers
|
|||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Produces(typeof(DbSet<Customer>))]
|
[Produces(typeof(DbSet<Customer>))]
|
||||||
|
[ResponseCache(Duration = 60)]
|
||||||
public IActionResult GetCustomer()
|
public IActionResult GetCustomer()
|
||||||
{
|
{
|
||||||
var results = new ObjectResult(_customerRepository.GetAll())
|
var results = new ObjectResult(_customerRepository.GetAll())
|
||||||
@ -40,6 +41,7 @@ namespace HPlusSportsAPI.Controllers
|
|||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Produces(typeof(Customer))]
|
[Produces(typeof(Customer))]
|
||||||
|
[ResponseCache(Duration = 60)]
|
||||||
public async Task<IActionResult> GetCustomer([FromRoute] int id)
|
public async Task<IActionResult> GetCustomer([FromRoute] int id)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
|
|||||||
@ -36,6 +36,8 @@ namespace H_Plus_Sports
|
|||||||
services.AddScoped<IProductRepository, ProductRepository>();
|
services.AddScoped<IProductRepository, ProductRepository>();
|
||||||
services.AddScoped<ISalespersonRepository, SalespersonRepository>();
|
services.AddScoped<ISalespersonRepository, SalespersonRepository>();
|
||||||
|
|
||||||
|
services.AddResponseCaching();
|
||||||
|
|
||||||
services.AddMvc(option => option.EnableEndpointRouting = false)
|
services.AddMvc(option => option.EnableEndpointRouting = false)
|
||||||
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
|
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
|
||||||
.AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
|
.AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
|
||||||
@ -53,6 +55,8 @@ namespace H_Plus_Sports
|
|||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.UseResponseCaching();
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|||||||
Reference in New Issue
Block a user