简体   繁体   English

State用Session管理,Asp.NET中缓存(MVC)

[英]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.使用ASP.NET MVC3创建一个Web App,基本框架包括NHibernate(Fluent),Ninject,Razor,Automapper,Jquery,Rhino-Security。

Need to decide upon State Management Stratety (Session and Cache level).需要决定 State 管理策略(会话和缓存级别)。 I have heard of following caching types,我听说过以下缓存类型,

  1. Output Cache Output 缓存
  2. Donut (Hole) Caching甜甜圈(孔)缓存
  3. Data Caching数据缓存

Considering a general scenario, I want to understand State Management policy to be used during a request,考虑到一般情况,我想了解 State 请求期间要使用的管理策略,

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)用户访问站点,仍然未经身份验证,因此通过 FormsAuth 模块重定向到登录页面(问题 - 由于登录页面没有特定于用户,绝对是 Output 缓存的候选者。但是视图是纯 HTML 由 MVC 逐字刷新,所以任何好处通过使用缓存)

PAGE ACCESS页面访问

  1. As I am using Rhino Security, navigation depends on Permissions assigned to individal User.当我使用 Rhino Security 时,导航取决于分配给各个用户的权限。 Each user MAY HAVE specific permissions assigned BUT most of users would have permissions as assigned to UseGroup to which that user belongs.每个用户都可以分配特定的权限,大多数用户将拥有分配给该用户所属的 UseGroup 的权限。 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)导航创建是一个两步过程 - 为用户获取权限集和生成导航 UI,所以这是我的两个问题(问题 1 - 在每个页面访问权限时都需要当前用户的权限以进行操作授权和导航创建,所以在哪里存储它 - Session?问题 2 - 也可以为每个用户创建首次访问的导航并存储在 session 中,但我们知道它对于用户组中的每个用户都是相同的,除非给出特定的用户。所以,我们可以创建Hash 用于一组特定的权限,然后将导航保存到数据缓存启用 Output 在负责创建导航 UI 的子操作上使用 VarByCustom 缓存)

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事实上,我确实有更多问题,但让我先看看 smbdy 是否真的费心在这里阅读这么多废话

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.这样,您只需第一次从数据库中检索它们,因为它将存储在 HttpContext.Current.Cache 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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