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 – 我必须附加什么进程才能使用IIS Express配置
- asp.net-mvc-3 – 为什么Visual Studio不会破坏这个未处理的
- asp.net-mvc – MVC动作过滤器集合已修改;枚举操作可能无法
- asp.net – 将初始空行插入到选择列表MVC LINQ SQL中
- asp.net-mvc – 将EF 4.1代码首先将ASP.NET MVC3部署到中等
- asp.net – 如何设置表单身份验证cookie路径
- asp.net-mvc – 实体类型处于“阴影状态”是什么意思?
- asp.net-mvc – ASP.NET MVC2母版页 – 服务器端脚本无法渲
- asp.net – 如何关闭我在JavaScript中打开的所有IE浏览器窗
- asp.net-mvc – 使用MVC和WebAPI避免使用Resharper web.con
- .net – 基于属性值的Ninject条件绑定
- asp.net-mvc – MVC DateTime验证失败
- asp.net-mvc – 为Orchard创建一个模块,用于存储
- ASP.NET会员盐?
- asp.net-mvc-3 – ASP.NET MVC 3 WebGrid – 条件
- asp.net-mvc – ASP.NET MVC UpdateModel容易受到
- asp.net – 您如何看待Postgres和Firebird数据库
- asp.net – 如何在加载/性能测试期间找到IIS要模
- 白话ASP.NET MVC之二:Controller激活系统的概览
- asp.net-mvc – 用于对Office 365 AD进行身份验证