From aca73d56ef004b6760be2fe8ffbd8cfd45326cbd Mon Sep 17 00:00:00 2001 From: Collin Barrett Date: Mon, 10 Sep 2018 21:15:43 -0500 Subject: [PATCH] bump in-memory and response caching to 1 day ref #481 --- .../Extensions/ConfigureServicesCollection.cs | 1 + src/FilterLists.Api/V1/Controllers/BaseController.cs | 3 ++- src/FilterLists.Api/V1/Controllers/DependentsController.cs | 2 +- src/FilterLists.Api/V1/Controllers/ForksController.cs | 2 +- src/FilterLists.Api/V1/Controllers/LanguagesController.cs | 4 ++-- src/FilterLists.Api/V1/Controllers/LicensesController.cs | 2 +- src/FilterLists.Api/V1/Controllers/ListsController.cs | 6 +++--- .../V1/Controllers/ListsLanguagesController.cs | 2 +- .../V1/Controllers/ListsMaintainersController.cs | 2 +- src/FilterLists.Api/V1/Controllers/ListsTagsController.cs | 2 +- src/FilterLists.Api/V1/Controllers/MaintainersController.cs | 2 +- src/FilterLists.Api/V1/Controllers/MergesController.cs | 2 +- src/FilterLists.Api/V1/Controllers/RulesController.cs | 2 +- src/FilterLists.Api/V1/Controllers/SoftwareController.cs | 4 ++-- .../V1/Controllers/SoftwareSyntaxesController.cs | 2 +- src/FilterLists.Api/V1/Controllers/SyntaxesController.cs | 2 +- src/FilterLists.Api/V1/Controllers/TagsController.cs | 2 +- 17 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/FilterLists.Api/DependencyInjection/Extensions/ConfigureServicesCollection.cs b/src/FilterLists.Api/DependencyInjection/Extensions/ConfigureServicesCollection.cs index 221ec482f..c007e0a60 100644 --- a/src/FilterLists.Api/DependencyInjection/Extensions/ConfigureServicesCollection.cs +++ b/src/FilterLists.Api/DependencyInjection/Extensions/ConfigureServicesCollection.cs @@ -16,6 +16,7 @@ public static void AddFilterListsApi(this IServiceCollection services) { services.ConfigureCookiePolicy(); services.AddMemoryCache(); + services.AddResponseCaching(); services.AddMvcCustom(); services.AddRoutingCustom(); services.AddApiVersioning(); diff --git a/src/FilterLists.Api/V1/Controllers/BaseController.cs b/src/FilterLists.Api/V1/Controllers/BaseController.cs index e77e4d6fb..bb0714d06 100644 --- a/src/FilterLists.Api/V1/Controllers/BaseController.cs +++ b/src/FilterLists.Api/V1/Controllers/BaseController.cs @@ -8,9 +8,10 @@ namespace FilterLists.Api.V1.Controllers [ApiVersion("1.0")] //TODO: use versioning without needing to manually specify in swagger-ui (https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/370) [Route("v{version:apiVersion}/[controller]")] + [ResponseCache(Duration = 86400)] public class BaseController : Controller { - protected static readonly TimeSpan FourHoursFromNow = TimeSpan.FromHours(4); + protected static readonly TimeSpan MemoryCacheDurationDefault = TimeSpan.FromDays(1); protected readonly IMemoryCache MemoryCache; protected readonly SeedService SeedService; diff --git a/src/FilterLists.Api/V1/Controllers/DependentsController.cs b/src/FilterLists.Api/V1/Controllers/DependentsController.cs index 433c76c79..5e3fc787c 100644 --- a/src/FilterLists.Api/V1/Controllers/DependentsController.cs +++ b/src/FilterLists.Api/V1/Controllers/DependentsController.cs @@ -17,7 +17,7 @@ public DependentsController(IMemoryCache memoryCache, SeedService seedService) : public async Task Seed() => Json(await MemoryCache.GetOrCreate("DependentsController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync(typeof(Dependent).GetProperty("DependentFilterListId"), typeof(Dependent).GetProperty("DependencyFilterListId")); })); diff --git a/src/FilterLists.Api/V1/Controllers/ForksController.cs b/src/FilterLists.Api/V1/Controllers/ForksController.cs index b94722064..848446004 100644 --- a/src/FilterLists.Api/V1/Controllers/ForksController.cs +++ b/src/FilterLists.Api/V1/Controllers/ForksController.cs @@ -17,7 +17,7 @@ public ForksController(IMemoryCache memoryCache, SeedService seedService) : base public async Task Seed() => Json(await MemoryCache.GetOrCreate("ForksController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync(typeof(Fork).GetProperty("UpstreamFilterListId"), typeof(Fork).GetProperty("ForkFilterListId")); })); diff --git a/src/FilterLists.Api/V1/Controllers/LanguagesController.cs b/src/FilterLists.Api/V1/Controllers/LanguagesController.cs index d64eeaf89..ee874696c 100644 --- a/src/FilterLists.Api/V1/Controllers/LanguagesController.cs +++ b/src/FilterLists.Api/V1/Controllers/LanguagesController.cs @@ -19,7 +19,7 @@ public LanguagesController(IMemoryCache memoryCache, SeedService seedService, La public async Task Index() => Json(await MemoryCache.GetOrCreate("LanguageService_Index", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return languageService.GetAllTargeted(); })); @@ -27,7 +27,7 @@ public async Task Index() => public async Task Seed() => Json(await MemoryCache.GetOrCreate("LanguagesController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync(); })); } diff --git a/src/FilterLists.Api/V1/Controllers/LicensesController.cs b/src/FilterLists.Api/V1/Controllers/LicensesController.cs index abec11da4..74b923b79 100644 --- a/src/FilterLists.Api/V1/Controllers/LicensesController.cs +++ b/src/FilterLists.Api/V1/Controllers/LicensesController.cs @@ -17,7 +17,7 @@ public LicensesController(IMemoryCache memoryCache, SeedService seedService) : b public async Task Seed() => Json(await MemoryCache.GetOrCreate("LicensesController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync(); })); } diff --git a/src/FilterLists.Api/V1/Controllers/ListsController.cs b/src/FilterLists.Api/V1/Controllers/ListsController.cs index d40947d97..2661472d5 100644 --- a/src/FilterLists.Api/V1/Controllers/ListsController.cs +++ b/src/FilterLists.Api/V1/Controllers/ListsController.cs @@ -19,7 +19,7 @@ public ListsController(IMemoryCache memoryCache, SeedService seedService, Filter public async Task Index() => Json(await MemoryCache.GetOrCreate("ListsController_Index", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return filterListService.GetAllSummariesAsync(); })); @@ -29,7 +29,7 @@ public async Task Index() => public async Task GetById(int id) => Json(await MemoryCache.GetOrCreate("ListsController_GetById_" + id, entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return filterListService.GetDetailsAsync((uint)id); })); @@ -37,7 +37,7 @@ public async Task GetById(int id) => public async Task Seed() => Json(await MemoryCache.GetOrCreate("ListsController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync(); })); } diff --git a/src/FilterLists.Api/V1/Controllers/ListsLanguagesController.cs b/src/FilterLists.Api/V1/Controllers/ListsLanguagesController.cs index 4a1323ad6..b594521a3 100644 --- a/src/FilterLists.Api/V1/Controllers/ListsLanguagesController.cs +++ b/src/FilterLists.Api/V1/Controllers/ListsLanguagesController.cs @@ -18,7 +18,7 @@ public ListsLanguagesController(IMemoryCache memoryCache, SeedService seedServic public async Task Seed() => Json(await MemoryCache.GetOrCreate("ListsLanguagesController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync( typeof(FilterListLanguage).GetProperty("FilterListId"), typeof(FilterListLanguage).GetProperty("LanguageId")); diff --git a/src/FilterLists.Api/V1/Controllers/ListsMaintainersController.cs b/src/FilterLists.Api/V1/Controllers/ListsMaintainersController.cs index c5ac42245..abce0996c 100644 --- a/src/FilterLists.Api/V1/Controllers/ListsMaintainersController.cs +++ b/src/FilterLists.Api/V1/Controllers/ListsMaintainersController.cs @@ -18,7 +18,7 @@ public ListsMaintainersController(IMemoryCache memoryCache, SeedService seedServ public async Task Seed() => Json(await MemoryCache.GetOrCreate("ListsMaintainersController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync( typeof(FilterListMaintainer).GetProperty("MaintainerId"), typeof(FilterListMaintainer).GetProperty("FilterListId")); diff --git a/src/FilterLists.Api/V1/Controllers/ListsTagsController.cs b/src/FilterLists.Api/V1/Controllers/ListsTagsController.cs index 4cccf5fea..6cd4fde76 100644 --- a/src/FilterLists.Api/V1/Controllers/ListsTagsController.cs +++ b/src/FilterLists.Api/V1/Controllers/ListsTagsController.cs @@ -18,7 +18,7 @@ public ListsTagsController(IMemoryCache memoryCache, SeedService seedService) public async Task Seed() => Json(await MemoryCache.GetOrCreate("ListsTagsController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync( typeof(FilterListTag).GetProperty("FilterListId"), typeof(FilterListTag).GetProperty("TagId")); diff --git a/src/FilterLists.Api/V1/Controllers/MaintainersController.cs b/src/FilterLists.Api/V1/Controllers/MaintainersController.cs index d519dd2ed..c3dde3429 100644 --- a/src/FilterLists.Api/V1/Controllers/MaintainersController.cs +++ b/src/FilterLists.Api/V1/Controllers/MaintainersController.cs @@ -17,7 +17,7 @@ public MaintainersController(IMemoryCache memoryCache, SeedService seedService) public async Task Seed() => Json(await MemoryCache.GetOrCreate("MaintainersController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync(); })); } diff --git a/src/FilterLists.Api/V1/Controllers/MergesController.cs b/src/FilterLists.Api/V1/Controllers/MergesController.cs index aa3068c97..59013ffde 100644 --- a/src/FilterLists.Api/V1/Controllers/MergesController.cs +++ b/src/FilterLists.Api/V1/Controllers/MergesController.cs @@ -17,7 +17,7 @@ public MergesController(IMemoryCache memoryCache, SeedService seedService) : bas public async Task Seed() => Json(await MemoryCache.GetOrCreate("MergesController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync(typeof(Merge).GetProperty("MergeFilterListId"), typeof(Merge).GetProperty("UpstreamFilterListId")); })); diff --git a/src/FilterLists.Api/V1/Controllers/RulesController.cs b/src/FilterLists.Api/V1/Controllers/RulesController.cs index 111980852..4105c87dc 100644 --- a/src/FilterLists.Api/V1/Controllers/RulesController.cs +++ b/src/FilterLists.Api/V1/Controllers/RulesController.cs @@ -16,7 +16,7 @@ public RulesController(IMemoryCache memoryCache, RuleService ruleService) : base public async Task Index() => Json(await MemoryCache.GetOrCreate("RulesController_Index", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return ruleService.GetCountAll(); })); } diff --git a/src/FilterLists.Api/V1/Controllers/SoftwareController.cs b/src/FilterLists.Api/V1/Controllers/SoftwareController.cs index dc231eb57..72a389ee3 100644 --- a/src/FilterLists.Api/V1/Controllers/SoftwareController.cs +++ b/src/FilterLists.Api/V1/Controllers/SoftwareController.cs @@ -19,7 +19,7 @@ public SoftwareController(IMemoryCache memoryCache, SeedService seedService, Sof public async Task Index() => Json(await MemoryCache.GetOrCreate("SoftwareController_Index", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return softwareService.GetAll(); })); @@ -27,7 +27,7 @@ public async Task Index() => public async Task Seed() => Json(await MemoryCache.GetOrCreate("SoftwareController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync(); })); } diff --git a/src/FilterLists.Api/V1/Controllers/SoftwareSyntaxesController.cs b/src/FilterLists.Api/V1/Controllers/SoftwareSyntaxesController.cs index d0a3f1778..2dfa41e85 100644 --- a/src/FilterLists.Api/V1/Controllers/SoftwareSyntaxesController.cs +++ b/src/FilterLists.Api/V1/Controllers/SoftwareSyntaxesController.cs @@ -18,7 +18,7 @@ public SoftwareSyntaxesController(IMemoryCache memoryCache, SeedService seedServ public async Task Seed() => Json(await MemoryCache.GetOrCreate("SoftwareSyntaxesController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync( typeof(SoftwareSyntax).GetProperty("SyntaxId"), typeof(SoftwareSyntax).GetProperty("SoftwareId")); })); diff --git a/src/FilterLists.Api/V1/Controllers/SyntaxesController.cs b/src/FilterLists.Api/V1/Controllers/SyntaxesController.cs index 2dec18a3b..b82325516 100644 --- a/src/FilterLists.Api/V1/Controllers/SyntaxesController.cs +++ b/src/FilterLists.Api/V1/Controllers/SyntaxesController.cs @@ -17,7 +17,7 @@ public SyntaxesController(IMemoryCache memoryCache, SeedService seedService) : b public async Task Seed() => Json(await MemoryCache.GetOrCreate("SyntaxesController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync(); })); } diff --git a/src/FilterLists.Api/V1/Controllers/TagsController.cs b/src/FilterLists.Api/V1/Controllers/TagsController.cs index ca19b50d0..5c75a0d07 100644 --- a/src/FilterLists.Api/V1/Controllers/TagsController.cs +++ b/src/FilterLists.Api/V1/Controllers/TagsController.cs @@ -17,7 +17,7 @@ public TagsController(IMemoryCache memoryCache, SeedService seedService) : base( public async Task Seed() => Json(await MemoryCache.GetOrCreate("TagsController_Seed", entry => { - entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault; return SeedService.GetAllAsync(); })); }