ASP.NET MVC捆绑缓存. (检测css文件更改)(内部行为)
|
我一直潜入ASP.NET MVC内部功能(不同的原因),但仍然无法涵盖所有的行为.其中一个我不是subj. 它的工作原理如下: 如果我捆绑一些文件(例如css文件),框架会检测到这些更改,并为新的软件包生成新的ID(使浏览器可以轻松刷新更改),如href =“/ Content / css?v = qartPE4jGe- l1U0I7kNDZPZzVTdh0kT8VBZZA_uURjI1” . 我实际上想了解什么: >框架(这可能不是MVC但.NET东西)检测到文件是如何改变的(因为没有目录观察者活动(因为我可以更改文件,即使在Web服务器离线),以查看文件改变生活,并且系统实际上检测到文件内容的变化(我尝试只是重新保存文件而不改变它们的内容,包编号也没有改变))? 非常感谢! 解决方法ASP.NET Optimization框架缓存HttpContext.Cache中的bundle响应,并使用 CacheDependency监控bundle中的每个文件以进行更改.这就是为什么更新文件直接使缓存失效并重新生成捆绑包.捆绑文件名是捆绑内容的哈希值,用于确保任何捆绑文件被修改时URL改变.软件包的虚拟路径用作缓存密钥. 图书馆的相关代码(注意这个稍微过时,但我认为逻辑仍然是一样的): internal BundleResponse GetBundleResponse(BundleContext context)
{
// check to see if the bundle response is in the cache
BundleResponse bundleResponse = Bundle.CacheLookup(context);
if (bundleResponse == null || context.EnableInstrumentation)
{
// if not,generate the bundle response and cache it
bundleResponse = this.GenerateBundleResponse(context);
if (context.UseServerCache)
{
this.UpdateCache(context,bundleResponse);
}
}
return bundleResponse;
}
private void UpdateCache(BundleContext context,BundleResponse response)
{
if (context.UseServerCache)
{
// create a list of all the file paths in the bundle
List<string> list = new List<string>();
list.AddRange(
from f in response.Files
select f.FullName);
list.AddRange(context.CacheDependencyDirectories);
string cacheKey = Bundle.GetCacheKey(context.BundleVirtualPath);
// insert the response into the cache with a cache dependency that monitors
// the bundle files for changes
context.HttpContext.Cache.Insert(cacheKey,response,new CacheDependency(list.ToArray()));
context.HttpContext.Response.AddCacheItemDependency(cacheKey);
this._cacheKeys.Add(cacheKey);
}
}
最后,对于旧的bundle URL,我想你会发现它们是从浏览器缓存返回的,或者实际上返回最新版本的捆绑包,因为捆绑路径没有改变,只有版本查询字符串. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – MVC 3 Ajax.ActionLink不能正常工作
- 缺少ASP.NET_SessionId
- asp.net-mvc-3 – asp.net mvc3请求线程亲和
- 有没有办法远程调用ASP.NET开发Web服务器?
- asp.net – 无法将HttpHandler映射到“路径/ *”通配符映射
- .net – Linq:获取DataContext中所有表的列表
- asp.net – 在模板化控件中实现级联DropDownList绑定
- 如何获取ASP.NET C#中请求的文件的MIME类型?
- 对于单个控件,asp.net – ValidateRequest =“false”
- asp.net-mvc – AspNet如何与我的模型识别
- 如何在ASP.NET MVC中手动设置用户的角色?
- asp.net-mvc – .input-validation-error为表单重
- mime-types – 在ASP.NET 5中使用MimeMapping(vN
- asp.net – 为什么IIS中的Windows /集成身份验证
- asp.net-mvc – ASP.NET MVC快速教程
- ASP.NET成员:拒绝用户阻止CSS,页面无法正确呈现
- asp.net-mvc – 在mvc中拖放文件
- asp.net-mvc – 为什么我的Html帮助者没有智能感
- 版本化ASP.NET Web应用程序
- asp.net-mvc – Server 2008 R2上的MVC – 如何?
