bump in-memory and response caching to 1 day

ref #481
This commit is contained in:
Collin Barrett 2018-09-10 21:15:43 -05:00
parent 7c3d0c2dad
commit aca73d56ef
17 changed files with 22 additions and 20 deletions

View file

@ -16,6 +16,7 @@ public static void AddFilterListsApi(this IServiceCollection services)
{
services.ConfigureCookiePolicy();
services.AddMemoryCache();
services.AddResponseCaching();
services.AddMvcCustom();
services.AddRoutingCustom();
services.AddApiVersioning();

View file

@ -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;

View file

@ -17,7 +17,7 @@ public DependentsController(IMemoryCache memoryCache, SeedService seedService) :
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("DependentsController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<Dependent, DependentSeedDto>(typeof(Dependent).GetProperty("DependentFilterListId"),
typeof(Dependent).GetProperty("DependencyFilterListId"));
}));

View file

@ -17,7 +17,7 @@ public ForksController(IMemoryCache memoryCache, SeedService seedService) : base
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("ForksController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<Fork, ForkSeedDto>(typeof(Fork).GetProperty("UpstreamFilterListId"),
typeof(Fork).GetProperty("ForkFilterListId"));
}));

View file

@ -19,7 +19,7 @@ public LanguagesController(IMemoryCache memoryCache, SeedService seedService, La
public async Task<IActionResult> Index() =>
Json(await MemoryCache.GetOrCreate("LanguageService_Index", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return languageService.GetAllTargeted();
}));
@ -27,7 +27,7 @@ public async Task<IActionResult> Index() =>
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("LanguagesController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<Language, LanguageSeedDto>();
}));
}

View file

@ -17,7 +17,7 @@ public LicensesController(IMemoryCache memoryCache, SeedService seedService) : b
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("LicensesController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<License, LicenseSeedDto>();
}));
}

View file

@ -19,7 +19,7 @@ public ListsController(IMemoryCache memoryCache, SeedService seedService, Filter
public async Task<IActionResult> Index() =>
Json(await MemoryCache.GetOrCreate("ListsController_Index", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return filterListService.GetAllSummariesAsync();
}));
@ -29,7 +29,7 @@ public async Task<IActionResult> Index() =>
public async Task<IActionResult> 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<IActionResult> GetById(int id) =>
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("ListsController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<FilterList, FilterListSeedDto>();
}));
}

View file

@ -18,7 +18,7 @@ public ListsLanguagesController(IMemoryCache memoryCache, SeedService seedServic
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("ListsLanguagesController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<FilterListLanguage, FilterListLanguageSeedDto>(
typeof(FilterListLanguage).GetProperty("FilterListId"),
typeof(FilterListLanguage).GetProperty("LanguageId"));

View file

@ -18,7 +18,7 @@ public ListsMaintainersController(IMemoryCache memoryCache, SeedService seedServ
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("ListsMaintainersController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<FilterListMaintainer, FilterListMaintainerSeedDto>(
typeof(FilterListMaintainer).GetProperty("MaintainerId"),
typeof(FilterListMaintainer).GetProperty("FilterListId"));

View file

@ -18,7 +18,7 @@ public ListsTagsController(IMemoryCache memoryCache, SeedService seedService)
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("ListsTagsController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<FilterListTag, FilterListTagSeedDto>(
typeof(FilterListTag).GetProperty("FilterListId"),
typeof(FilterListTag).GetProperty("TagId"));

View file

@ -17,7 +17,7 @@ public MaintainersController(IMemoryCache memoryCache, SeedService seedService)
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("MaintainersController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<Maintainer, MaintainerSeedDto>();
}));
}

View file

@ -17,7 +17,7 @@ public MergesController(IMemoryCache memoryCache, SeedService seedService) : bas
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("MergesController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<Merge, MergeSeedDto>(typeof(Merge).GetProperty("MergeFilterListId"),
typeof(Merge).GetProperty("UpstreamFilterListId"));
}));

View file

@ -16,7 +16,7 @@ public RulesController(IMemoryCache memoryCache, RuleService ruleService) : base
public async Task<IActionResult> Index() =>
Json(await MemoryCache.GetOrCreate("RulesController_Index", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return ruleService.GetCountAll();
}));
}

View file

@ -19,7 +19,7 @@ public SoftwareController(IMemoryCache memoryCache, SeedService seedService, Sof
public async Task<IActionResult> Index() =>
Json(await MemoryCache.GetOrCreate("SoftwareController_Index", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return softwareService.GetAll();
}));
@ -27,7 +27,7 @@ public async Task<IActionResult> Index() =>
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("SoftwareController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<Software, SoftwareSeedDto>();
}));
}

View file

@ -18,7 +18,7 @@ public SoftwareSyntaxesController(IMemoryCache memoryCache, SeedService seedServ
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("SoftwareSyntaxesController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<SoftwareSyntax, SoftwareSyntaxSeedDto>(
typeof(SoftwareSyntax).GetProperty("SyntaxId"), typeof(SoftwareSyntax).GetProperty("SoftwareId"));
}));

View file

@ -17,7 +17,7 @@ public SyntaxesController(IMemoryCache memoryCache, SeedService seedService) : b
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("SyntaxesController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<Syntax, SyntaxSeedDto>();
}));
}

View file

@ -17,7 +17,7 @@ public TagsController(IMemoryCache memoryCache, SeedService seedService) : base(
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("TagsController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
entry.AbsoluteExpirationRelativeToNow = MemoryCacheDurationDefault;
return SeedService.GetAllAsync<Tag, TagSeedDto>();
}));
}