简体   繁体   中英

State management with Session and Cache in Asp.NET (MVC)

Creating a Web App using ASP.NET MVC3, essential framework includes NHibernate (Fluent), Ninject, Razor, Automapper, Jquery, Rhino-Security.

Need to decide upon State Management Stratety (Session and Cache level). I have heard of following caching types,

  1. Output Cache
  2. Donut (Hole) Caching
  3. Data Caching

Considering a general scenario, I want to understand State Management policy to be used during a request,

LOGIN

  1. User goes to site, is still Unauthenticated, so redireted to Login page by FormsAuth module (QUESTION - As Login page is no user specific, definitely a candidate for Output Cache. But then the View is pure HTML flushed verbatim by MVC, so any benefit by using cache)

PAGE ACCESS

  1. As I am using Rhino Security, navigation depends on Permissions assigned to individal User. Each user MAY HAVE specific permissions assigned BUT most of users would have permissions as assigned to UseGroup to which that user belongs. Navigation creation is so a two step process - Fetching permission set for user and Gernerating Navigation UI and so here are my two Qs ( QUESTION 1 - Permission for current user would be required at each page access for action authorization as well as navigation cretion, so where to store it - Session? QUESTION 2 - Navigation too MAY be created for each user for first access and stored in session, BUT we are aware it would be same for each user in a UserGroup unless given specific ones. So, we may create Hash for a certain set of permissions and then either save Navigation to Data Cache OR enable Output Cache using VarByCustom on Child action responsible for creating Nav UI)

I see i have been too verbose. In fact i do have more Questions, but let me see first if smbdy really bothers to read this much crap here

Regarding User Permissions, given they are the same for each User Group, I would store them in Cache like this:

if (System.Web.HttpContext.Current.Cache["UserGroup_1_Permissions"] == null)
{
    _Permissions = DAL.getPermissions("UserGroup1") as List<Permissions>;
    System.Web.HttpContext.Current.Cache["UserGroup_1_Permissions"] = _Permissions;
}
else
{
    _Permissions = System.Web.HttpContext.Current.Cache["UserGroup_1_Permissions"] as List<Permissions>;
}

This way, you would retrieve them from DB only first time, as it will get stored in HttpContext.Current.Cache.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM