asp.net-mvc-3 – mvc3 OutputCache RemoveOutputCacheItem Rende
|
我做了我的研究,但没有找到任何答案. 我在主页面中使用Html.RenderAction(用于呈现具有特定于用户权限的链接的页眉). Action使用OutputCache修饰,返回部分控制并按预期缓存. 当事件发生时(假设权限已更改)我想以编程方式使缓存的部分控件无效. 我正在尝试使用RemoveOutputCacheItem方法.它将路径作为参数.我正在尝试设置Html.RenderAction中使用的操作的路径.这不会使行动失效. 如何以编程方式使操作无效? 谢谢 解决方法子操作的缓存存储在 OutputCacheAttribute.ChildActionCache属性中.问题是,为子操作生成id并将其存储在此对象中的API不公开(为什么是微软?).因此,如果您尝试遍历此集合中的对象,您将发现它还将包含子操作的缓存值,但除非您反向设计用于生成键的算法,否则您将无法识别它像这样的东西(如Reflector所示):internal string GetChildActionUniqueId(ActionExecutingContext filterContext)
{
StringBuilder builder = new StringBuilder();
builder.Append("_MvcChildActionCache_");
builder.Append(filterContext.ActionDescriptor.UniqueId);
builder.Append(DescriptorUtil.CreateUniqueId(new object[] { this.VaryByCustom }));
if (!string.IsNullOrEmpty(this.VaryByCustom))
{
string varyByCustomString = filterContext.HttpContext.ApplicationInstance.GetVaryByCustomString(HttpContext.Current,this.VaryByCustom);
builder.Append(varyByCustomString);
}
builder.Append(GetUniqueIdFromActionParameters(filterContext,SplitVaryByParam(this.VaryByParam)));
using (SHA256 sha = SHA256.Create())
{
return Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(builder.ToString())));
}
}
所以你可以执行以下疯狂: public ActionResult Invalidate()
{
OutputCacheAttribute.ChildActionCache = new MemoryCache("NewDefault");
return View();
}
这显然会使所有缓存的子操作无效,这些操作可能不是您正在寻找的但我担心除了当然是对密钥生成进行逆向工程之外的唯一方法:-). @Microsoft,拜托,我求你了解ASP.NET MVC 4.0: >除了甜甜圈洞缓存之外,还介绍了进行甜甜圈缓存的可能性>介绍了轻松过期缓存控制器操作结果的可能性(比Response.RemoveOutputCacheItem更多MVCish)>介绍轻松过期缓存子操作的结果的可能性>如果你这样做1.那么显然有可能使缓存的甜甜圈部分到期. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – 如何为未经过身份验证的用户隐藏
- asp.net – Server.Transfer throws执行子请求时
- asp.net-mvc-3 – 处理DbContext后的问题
- 了解asp.net中的负载平衡
- asp.net-mvc – asp.net mvc排除来自搜索引擎抓取
- asp.net-mvc – 如何通过属性过滤器在MVC中设置R
- asp.net – JQGrid不显示数据
- asp.net – WCF:是否有一个属性要在OperationCo
- asp.net-mvc – DevExpress MVC GridView – 如何
- asp.net-mvc – 有什么图形设计器ASP.NET MVC吗?
