/// <summary> /// 检查和移除缓存 /// </summary> /// <param name="instance"></param> /// <returns></returns> public static YannyoCache CheckAndRemoveCache(YannyoCache instance)// { //当程序运行中cache.config发生变化时则对缓存对象做删除的操作 cachefilenewchange = System.IO.File.GetLastWriteTime(path); if (cachefileoldchange != cachefilenewchange) { lock (cachelockHelper) { if (cachefileoldchange != cachefilenewchange) { //当有要清除的项时 DataSet dsSrc = new DataSet(); dsSrc.ReadXml(path); foreach (DataRow dr in dsSrc.Tables[0].Rows) { if (dr["xpath"].ToString().Trim() != "") { DateTime removedatetime = DateTime.Now; try { removedatetime = Convert.ToDateTime(dr["removedatetime"].ToString().Trim()); } catch { ; } if (removedatetime > cachefilenewchange.AddSeconds(-2)) { string xpath = dr["xpath"].ToString().Trim(); instance.RemoveObject(xpath, false); } } } cachefileoldchange = cachefilenewchange; dsSrc.Dispose(); } } } return(instance); }