[OutputCache(Duration = PresetLang.CACHE_DURATION, VaryByCustom = "HomeIndex")]
public ActionResult Index()
{
Response.Cache.SetOmitVaryStar(true);
}
Global.asax.cs
//已用户当前的URL作为缓存Key
public override string GetVaryByCustomString(System.Web.HttpContext context, string custom)
{
var urlCache = WebCache.Get<string>(context.Request.Url.Host);
if (urlCache == null)
{
urlCache = string.Format("{0}{1}", context.Request.Url.ToString(), Guid.NewGuid());
WebCache.Add<string>(context.Request.Url.Host, urlCache);
}
return urlCache;
//string requestUrl = context.Request.Url.ToString();
//return requestUrl;
}
本文介绍了一个ASP.NET MVC应用程序中使用的缓存机制,包括如何设置缓存以忽略某些变化,并通过使用GUID来为每个请求创建唯一的缓存键,确保了缓存的有效性和独特性。
2613

被折叠的 条评论
为什么被折叠?



