Add HTTP/2 Push to Output Cache

This commit is contained in:
Thomas Hounsell 2016-08-21 21:49:38 +01:00
parent 7901300c30
commit 9100ba6673
3 changed files with 40 additions and 12 deletions

View File

@ -192,6 +192,7 @@
<Compile Include="Code\MvcIntrinsics.cs" />
<Compile Include="Code\Options\Locale.cs" />
<Compile Include="Code\Options\Theme.cs" />
<Compile Include="Code\OutputCachePushAttribute.cs" />
<Compile Include="Controllers\ApiController.cs" />
<Compile Include="Controllers\BaseController.cs" />
<Compile Include="Controllers\FrontController.cs" />

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BuildFeed.Code.Options;
namespace BuildFeed.Code
{
public class OutputCachePushAttribute: ActionFilterAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
bool isRtl = CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft;
Theme theme = new Theme(Theme.DetectTheme(filterContext.HttpContext));
filterContext.HttpContext.Response.PushPromise("/res/css/default.min.css");
filterContext.HttpContext.Response.PushPromise(VirtualPathUtility.ToAbsolute(theme.CssPath));
if (isRtl)
{
filterContext.HttpContext.Response.PushPromise("/res/css/rtl.min.css");
}
filterContext.HttpContext.Response.PushPromise("/res/ts/bfs.min.js");
}
}
}

View File

@ -29,7 +29,7 @@ public FrontController()
[Route("", Order = 1)]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme")]
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme"), OutputCachePush(Order = 2)]
#endif
public async Task<ActionResult> Index()
{
@ -39,7 +39,7 @@ public async Task<ActionResult> Index()
[Route("page-{page:int:min(1)}/", Order = 0)]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "page", VaryByCustom = "userName;lang;theme")]
[OutputCache(Duration = 600, VaryByParam = "page", VaryByCustom = "userName;lang;theme"), OutputCachePush(Order = 2)]
#endif
public async Task<ActionResult> IndexPage(int page)
{
@ -59,7 +59,7 @@ public async Task<ActionResult> IndexPage(int page)
[Route("group/{major}.{minor}.{number}.{revision}/", Order = 1)]
[Route("group/{major}.{minor}.{number}/", Order = 5)] // for when there is no revision
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme")]
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme"), OutputCachePush(Order = 2)]
#endif
public async Task<ActionResult> ViewGroup(uint major, uint minor, uint number, uint? revision = null)
{
@ -84,7 +84,7 @@ public async Task<ActionResult> ViewGroup(uint major, uint minor, uint number, u
[Route("build/{id:guid}/", Name = "Build")]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme")]
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme"), OutputCachePush(Order = 2)]
#endif
public async Task<ActionResult> ViewBuild(Guid id)
{
@ -184,7 +184,7 @@ public async Task<ActionResult> TwitterCard(long id)
[Route("lab/{lab}/", Order = 1, Name = "Lab Root")]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme")]
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme"), OutputCachePush(Order = 2)]
#endif
public async Task<ActionResult> ViewLab(string lab)
{
@ -193,7 +193,7 @@ public async Task<ActionResult> ViewLab(string lab)
[Route("lab/{lab}/page-{page:int:min(2)}/", Order = 0)]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "page", VaryByCustom = "userName;lang;theme")]
[OutputCache(Duration = 600, VaryByParam = "page", VaryByCustom = "userName;lang;theme"), OutputCachePush(Order = 2)]
#endif
public async Task<ActionResult> ViewLabPage(string lab, int page)
{
@ -219,7 +219,7 @@ public async Task<ActionResult> ViewLabPage(string lab, int page)
[Route("source/{source}/", Order = 1, Name = "Source Root")]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme")]
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme"), OutputCachePush(Order = 2)]
#endif
public async Task<ActionResult> ViewSource(TypeOfSource source)
{
@ -228,7 +228,7 @@ public async Task<ActionResult> ViewSource(TypeOfSource source)
[Route("source/{source}/page-{page:int:min(2)}/", Order = 0)]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "page", VaryByCustom = "userName;lang;theme")]
[OutputCache(Duration = 600, VaryByParam = "page", VaryByCustom = "userName;lang;theme"), OutputCachePush(Order = 2)]
#endif
public async Task<ActionResult> ViewSourcePage(TypeOfSource source, int page)
{
@ -254,7 +254,7 @@ public async Task<ActionResult> ViewSourcePage(TypeOfSource source, int page)
[Route("year/{year}/", Order = 1, Name = "Year Root")]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme")]
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme"), OutputCachePush(Order = 2)]
#endif
public async Task<ActionResult> ViewYear(int year)
{
@ -263,7 +263,7 @@ public async Task<ActionResult> ViewYear(int year)
[Route("year/{year}/page-{page:int:min(2)}/", Order = 0)]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "page", VaryByCustom = "userName;lang;theme")]
[OutputCache(Duration = 600, VaryByParam = "page", VaryByCustom = "userName;lang;theme"), OutputCachePush(Order = 2)]
#endif
public async Task<ActionResult> ViewYearPage(int year, int page)
{
@ -289,7 +289,7 @@ public async Task<ActionResult> ViewYearPage(int year, int page)
[Route("version/{major}.{minor}/", Order = 1, Name = "Version Root")]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme")]
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme"), OutputCachePush(Order = 2)]
#endif
public async Task<ActionResult> ViewVersion(uint major, uint minor)
{
@ -298,7 +298,7 @@ public async Task<ActionResult> ViewVersion(uint major, uint minor)
[Route("version/{major}.{minor}/page-{page:int:min(2)}/", Order = 0)]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme")]
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName;lang;theme"), OutputCachePush(Order = 2)]
#endif
public async Task<ActionResult> ViewVersionPage(uint major, uint minor, int page)
{