清除服务器缓存办法//在ashx文件中写方法
/// <summary>/// ServerMgr 的摘要说明/// </summary>public class ServerMgr : IHttpHandler{public void ProcessRequest(HttpContext context){object returnObj = "";string method = context.Request["Method"];switch (method){case "clearCache": returnObj = ClearCache(context);PageHelper.ReturnAjaxData(context,returnObj.ToString());break;default:PageHelper.ReturnAjaxData(context,"操作失败!");break;}}/// <summary>/// 清除服务器缓存/// </summary>public string ClearCache(HttpContext context){IDictionaryEnumerator enumerator = HttpRuntime.Cache.GetEnumerator();List<string> keys = new List<string>();while (enumerator.MoveNext()){keys.Add(enumerator.Key.ToString());}for (int i = 0; i < keys.Count; i++){HttpRuntime.Cache.Remove(keys[i]);}if (HttpRuntime.Cache.Count == 0)return "刷新成功";elsereturn "刷新失败!";}public bool IsReusable{get{return false;}}}
}//js文件
var $c = new Object();
$c.frushCache = function () {if (confirm("确定清除缓存?"))if (window.location.host.indexOf("localhost") > -1)AjaxData.GetAjaxData("http://localhost:8088/Ashx/ServerMgr.ashx", { Method: 'clearCache' }, function (data) { alert(JSON.stringify(data)); }, null, null);elseAjaxData.GetAjaxData("https://www.baidu.com/Ashx/ServerMgr.ashx", { Method: 'clearCache' }, function (data) { alert(JSON.stringify(data)); }, null, null);//html 调用
<a href="javascript:$c.frushCache()">刷新网站服务器缓存</a>