MVC4捆绑缓存头 [英] MVC4 Bundling Cache Headers

查看:142
本文介绍了MVC4捆绑缓存头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变一个包请求发出的缓存头。目前,它是由用户代理不同,但我不希望它,有没有办法改变一个包请求发送的头?

I want to change the cache headers sent from a bundle request. Currently it is varying by User-Agent but I don't want it to, is there a way to change the headers sent by a bundle request?

在快速浏览一下在 System.Web.Optimization 组装可以看我的头得到设定 Bundle.SetHeaders 这是一个私有的静态函数,所以我不认为它可能,虽然我很乐意被证明是错误的。

After a quick look in the System.Web.Optimization assembly I can see the headers get set in Bundle.SetHeaders which is a private static function so I don't think its possible although I would love to be proven wrong.

推荐答案

这是不是我们今天当前公开。我们只能暴露在BundleRepsonse可缓存属性,一个IBundleTransform可能改变。是的,我们明确地设置了以下几件事:

This isn't something that we currently expose today. We only expose the Cacheability property on the BundleRepsonse that a IBundleTransform could change. And yes we explicitly set the following things:

                HttpCachePolicyBase cachePolicy = context.HttpContext.Response.Cache;
                cachePolicy.SetCacheability(bundleResponse.Cacheability);
                cachePolicy.SetOmitVaryStar(true);
                cachePolicy.SetExpires(DateTime.Now.AddYears(1));
                cachePolicy.SetValidUntilExpires(true);
                cachePolicy.SetLastModified(DateTime.Now);
                cachePolicy.VaryByHeaders["User-Agent"] = true;

我们有一个工作项目积压我们开这件事,使这个更具扩展性/可定制的未来。

We have a work item our backlog to open this up and make this more extensible/customizable in the future.

这篇关于MVC4捆绑缓存头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆