Last active
August 29, 2015 14:06
-
-
Save brainded/20b623ddbcee3542afe5 to your computer and use it in GitHub Desktop.
Utilize Output Cache with User Identity. Found on StackOverflow: http://stackoverflow.com/questions/17187736/output-cache-per-user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
using TwitterPoc.Services; | |
namespace BobsBurgers.Controllers | |
{ | |
public class BobsBurgersController : Controller | |
{ | |
//To use the user cache, the cache needs to be server side sadly | |
[OutputCache(VaryByCustom="User", Location = OutputCacheLocation.Server)] | |
public ActionResult Index() | |
{ | |
return View(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Http; | |
using System.Web.Mvc; | |
using System.Web.Optimization; | |
using System.Web.Routing; | |
namespace BobsBurgers | |
{ | |
public class WebApiApplication : System.Web.HttpApplication | |
{ | |
protected void Application_Start() | |
{ | |
... | |
} | |
public override string GetVaryByCustomString(HttpContext context, string custom) | |
{ | |
if (custom.Equals("User", StringComparison.InvariantCultureIgnoreCase)) | |
{ | |
return string.Format("User:{0}", context.User.Identity.Name); | |
} | |
return base.GetVaryByCustomString(context, custom); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment