Skip to content

Instantly share code, notes, and snippets.

@StefanoChiodino
Created November 22, 2016 12:44
Show Gist options
  • Save StefanoChiodino/25affa33580163d6bafbfe1043401c12 to your computer and use it in GitHub Desktop.
Save StefanoChiodino/25affa33580163d6bafbfe1043401c12 to your computer and use it in GitHub Desktop.
A controller that caches only get requests
public class CachedGetController : ControllerBase
{
[HttpGet]
[OutputCache(Duration = 600)]
public override ActionResult Index(RenderModel model)
{
return base.Index(model);
}
[HttpPost]
public ActionResult Index(RenderModel model, object obj = null)
{
return base.Index(model);
}
}
public abstract class ControllerBase : SurfaceController, IRenderMvcController
{
public virtual ActionResult Index(RenderModel model)
{
return this.CurrentTemplate(model);
}
private ActionResult CurrentTemplate(RenderModel model)
{
var template = this.ControllerContext.RouteData.Values["action"].ToString();
return this.View(template, model);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment