加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

如何清除正式环境中的缓存

发布时间:2020-12-15 21:14:00 所属栏目:asp.Net 来源:网络整理
导读:项目已经挂在了正式系统上,不断有用户在上面进行业务处理,现在在数据库中添加了一些新数据,而这些数据由于是基础数据,一般不会做变动,所以在项目中是采用缓存技术将整个表中的内容缓存起来的。现在用户需要马上看到这些更新的数据,那么就必须要清除缓

项目已经挂在了正式系统上,不断有用户在上面进行业务处理,现在在数据库中添加了一些新数据,而这些数据由于是基础数据,一般不会做变动,所以在项目中是采用缓存技术将整个表中的内容缓存起来的。现在用户需要马上看到这些更新的数据,那么就必须要清除缓存。由于项目已经是正式发布了,所以不可能用停IIS的方式来清除缓存。在项目中添加一个页面一个按钮,用程序来清除缓存是比较好的方法。由于不能停止系统,重新发布项目,那么可以直接登录到服务器上,在项目的文件夹下面建立一个文件clear.aspx。打开这个文件,输入如下内容:<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
<span style="COLOR: #008080">?1<img id="Codehighlighter1_2_22_Open_Image" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/02-14/22/405b18b4b6584ae338e0f6ecaf736533.gif" align="top"><img id="Codehighlighter1_2_22_Closed_Image" style="DISPLAY: none" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/02-14/22/1c53668bcee393edac0d7b3b3daff1ae.gif" align="top"><span style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"><%<span id="Codehighlighter1_2_22_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">

<img src="https://www.52php.cn/res/2019/02-14/22/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif"&gt;

<span id="Codehighlighter1_2_22_Open_Text"><span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">@?Page?Language<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">C#<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">?<span style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%><span style="COLOR: #000000"><span style="COLOR: #008080">?2<span style="COLOR: #000000"><img id="Codehighlighter1_28_67_Open_Image" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/02-14/22/405b18b4b6584ae338e0f6ecaf736533.gif" align="top"><img id="Codehighlighter1_28_67_Closed_Image" style="DISPLAY: none" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/02-14/22/1c53668bcee393edac0d7b3b3daff1ae.gif" align="top"><span style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"><%<span id="Codehighlighter1_28_67_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">

<img src="https://www.52php.cn/res/2019/02-14/22/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif"&gt;

<span id="Codehighlighter1_28_67_Open_Text"><span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">@?Import?Namespace<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">System.Web.Caching<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">?<span style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%><span style="COLOR: #000000"><span style="COLOR: #008080">?3<span style="COLOR: #000000">

<img src="https://www.52php.cn/res/2019/02-14/22/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">

<span style="COLOR: #0000ff"><!<span style="COLOR: #ff00ff">DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"<span style="COLOR: #0000ff">><span style="COLOR: #000000"><span style="COLOR: #008080">?4<span style="COLOR: #000000">

<img src="https://www.52php.cn/res/2019/02-14/22/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">

<span style="COLOR: #008080">?5<span style="COLOR: #000000"><img id="Codehighlighter1_217_706_Open_Image" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/02-14/22/405b18b4b6584ae338e0f6ecaf736533.gif" align="top"><img id="Codehighlighter1_217_706_Closed_Image" style="DISPLAY: none" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/02-14/22/1c53668bcee393edac0d7b3b3daff1ae.gif" align="top"><span style="COLOR: #0000ff"><<span style="COLOR: #800000">script?<span style="COLOR: #ff0000">runat<span style="COLOR: #0000ff">="server"<span style="COLOR: #0000ff">><span id="Codehighlighter1_217_706_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">

<img src="https://www.52php.cn/res/2019/02-14/22/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif"&gt;

<span id="Codehighlighter1_217_706_Open_Text"><span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><span style="COLOR: #008080">?6<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">

<img src="https://www.52php.cn/res/2019/02-14/22/33d02437d135341f0800e3d415312ae8.gif" align="top">

<span style="COLOR: #008080">?7<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">

<img src="https://www.52php.cn/res/2019/02-14/22/33d02437d135341f0800e3d415312ae8.gif" align="top">????protected?

<span style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">void<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">?Button1_Click(object?sender,?EventArgs?e)<span style="COLOR: #008080">?8<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><img id="Codehighlighter1_284_705_Open_Image" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/02-14/22/2887d91d0594ef8793c1db92b8a1d545.gif" align="top"><img id="Codehighlighter1_284_705_Closed_Image" style="DISPLAY: none" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/02-14/22/7a2b9a960ee9a98bfd25d306d55009f8.gif" align="top">????<span id="Codehighlighter1_284_705_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">

<img src="https://www.52php.cn/res/2019/02-14/22/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif"&gt;

<span id="Codehighlighter1_284_705_Open_Text"><span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">{<span style="COLOR: #008080">?9<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">

<img src="https://www.52php.cn/res/2019/02-14/22/33d02437d135341f0800e3d415312ae8.gif" align="top">????????Cache?cache?

<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">?HttpRuntime.Cache;<span style="COLOR: #008080">10<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">

<img src="https://www.52php.cn/res/2019/02-14/22/33d02437d135341f0800e3d415312ae8.gif" align="top">????????

<span style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">int<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">?count?<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">?cache.Count;<span style="COLOR: #008080">11<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">

<img src="https://www.52php.cn/res/2019/02-14/22/33d02437d135341f0800e3d415312ae8.gif" align="top">????????IDictionaryEnumerator?CacheEnum?

<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">?cache.GetEnumerator();<span style="COLOR: #008080">12<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">

<img src="https://www.52php.cn/res/2019/02-14/22/33d02437d135341f0800e3d415312ae8.gif" align="top">????????

<span style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">while<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">?(CacheEnum.MoveNext())<span style="COLOR: #008080">13<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><img id="Codehighlighter1_470_593_Open_Image" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/02-14/22/2887d91d0594ef8793c1db92b8a1d545.gif" align="top"><img id="Codehighlighter1_470_593_Closed_Image" style="DISPLAY: none" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/02-14/22/7a2b9a960ee9a98bfd25d306d55009f8.gif" align="top">????????<span id="Codehighlighter1_470_593_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">

<img src="https://www.52php.cn/res/2019/02-14/22/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif"&gt;

<span id="Codehighlighter1_470_593_Open_Text"><span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">{<span style="COLOR: #008080">14<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">

<img src="https://www.52php.cn/res/2019/02-14/22/33d02437d135341f0800e3d415312ae8.gif" align="top">????????????string?cacheItem?

<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">?Server.HtmlEncode(CacheEnum.Key.ToString());<span style="COLOR: #008080">15<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">

<img src="https://www.52php.cn/res/2019/02-14/22/33d02437d135341f0800e3d415312ae8.gif" align="top">????????????cache.Remove(cacheItem);

<span style="COLOR: #008080">16<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">

<img src="https://www.52php.cn/res/2019/02-14/22/105a1e124122b2abcee4ea8e9f5108f3.gif" align="top">????????}

<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><span style="COLOR: #008080">17<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">

<img src="https://www.52php.cn/res/2019/02-14/22/33d02437d135341f0800e3d415312ae8.gif" align="top">????????Response.Write(

<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">