mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
add in-memory caches to rules count endpoint
This commit is contained in:
parent
db09845c8a
commit
f720f83bdb
2 changed files with 14 additions and 2 deletions
|
|
@ -18,6 +18,11 @@ public BaseController()
|
|||
{
|
||||
}
|
||||
|
||||
protected BaseController(IMemoryCache memoryCache)
|
||||
{
|
||||
MemoryCache = memoryCache;
|
||||
}
|
||||
|
||||
protected BaseController(IMemoryCache memoryCache, SeedService seedService)
|
||||
{
|
||||
MemoryCache = memoryCache;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Threading.Tasks;
|
||||
using FilterLists.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace FilterLists.Api.V1.Controllers
|
||||
{
|
||||
|
|
@ -8,9 +9,15 @@ public class RulesController : BaseController
|
|||
{
|
||||
private readonly RuleService ruleService;
|
||||
|
||||
public RulesController(RuleService ruleService) => this.ruleService = ruleService;
|
||||
public RulesController(IMemoryCache memoryCache, RuleService ruleService) : base(memoryCache) =>
|
||||
this.ruleService = ruleService;
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Index() => Json(await ruleService.GetCountAll());
|
||||
public async Task<IActionResult> Index() =>
|
||||
Json(await MemoryCache.GetOrCreate("RulesController_Index", entry =>
|
||||
{
|
||||
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
|
||||
return ruleService.GetCountAll();
|
||||
}));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue