Service de cache de database fonctionnel
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using GrossesMitainesAPI.Data;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using GrossesMitainesAPI.Services;
|
||||
|
||||
namespace GrossesMitainesAPI.Controllers;
|
||||
|
||||
@@ -12,10 +13,12 @@ namespace GrossesMitainesAPI.Controllers;
|
||||
public class InventoryController : Controller {
|
||||
private readonly ILogger<InventoryController> _logger;
|
||||
private readonly InventoryContext _context;
|
||||
private readonly DatabaseCacheService _cache;
|
||||
|
||||
public InventoryController(ILogger<InventoryController> logger, InventoryContext context) {
|
||||
public InventoryController(ILogger<InventoryController> logger, InventoryContext context, DatabaseCacheService cache) {
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
[EnableCors("_myAllowSpecificOrigins")]
|
||||
@@ -23,7 +26,11 @@ public class InventoryController : Controller {
|
||||
public IEnumerable<Product> Get(int? lastId, string? order, string? filterPrice, string? filterState, bool? all) {
|
||||
const int AMOUNT = 5;
|
||||
|
||||
var ret = _context.Products.AsQueryable();
|
||||
IQueryable<Product> ret;
|
||||
|
||||
if (_cache.isOk())
|
||||
ret = _cache.GetCacheCopy().AsQueryable();
|
||||
else ret = _context.Products.AsQueryable();
|
||||
|
||||
switch (filterPrice) {
|
||||
case "PriceUnder20":
|
||||
|
Reference in New Issue
Block a user