简体   繁体   English

如何使用.Net清除缓存

[英]How to clear cache with .Net

I tell them my problem. 我告诉他们我的问题。 I have a fairly large site, where there are frequent changes. 我有一个相当大的站点,那里经常更改。 The same is made. 一样。 Net F 3.5. 净F 3.5。

My big problem is that every time I make a rise in production I have to send a mail to all the people who use that site to clean your browser history. 我的大问题是,每当我提高产量时,都必须向所有使用该网站的人发送邮件,以清理您的浏览器历史记录。 As it begins to have the same malfunction as it mixes the previous web with the latest version uploaded. 由于开始将以前的网站与上载的最新版本混合在一起时会出现相同的故障。

Is there any way to force a refresh of the page to a raise? 有什么方法可以强制刷新页面? but without disabling the cache? 但没有禁用缓存? Since layers increases are 1 per month and cache for the size of the web is very useful. 由于层数是每月增加1,因此缓存Web大小非常有用。

You should add a hash to the assets url. 您应该将哈希值添加到资产网址。

for example, if you need to include /scripts/yourscript.js , calculate the hash of the file and append it to the url: 例如,如果您需要包含/scripts/yourscript.js ,请计算文件的哈希并将其附加到url:

<script src="/scripts/yourscript.js?hash=XYZ"></script>

This way, the URL will be unique to the version of the file, and the browser will differentiate each version. 这样,URL对于文件的版本将是唯一的,并且浏览器将区分每个版本。 This will ensure the correct file is loaded. 这将确保加载正确的文件。

You can calculate the hash of the file, use a timestamp, or anything that can differentiate the versions. 您可以计算文件的哈希值,使用时间戳或任何可以区分版本的方法。

You can also play with http headers to set the caching policy. 您也可以使用http标头来设置缓存策略。 But the former advise is better (I think), because you can still combine caching benefits and versioning. 但是前者建议更好(我认为),因为您仍然可以将缓存优势和版本控制结合起来。

I think that the ScriptManager control can automatically do this hash for you (but I'm not sure) 我认为ScriptManager控件可以自动为您执行此哈希操作(但我不确定)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM