/// <summary> /// 初始化缓存 /// </summary> private void initDataCache() { try { long nLenSize = DataHelper.StructSize <DataLenNode>(); long nDataSize = DataHelper.StructSize <T>(); long mapCacheSize = this.mMaxDataCount * nDataSize + nLenSize; var dbFilePath = string.Format("{0}/{1}.dat", YunMapCacheHelper.getMapCacheRoot(), this.mCacheFileName); var mapName = string.Format("YunMapCache_{0}", this.mCacheFileName); this.mMapFile = MemoryMappedFile.CreateFromFile(dbFilePath, FileMode.OpenOrCreate, mapName, mapCacheSize); this.mMapStream = this.mMapFile.CreateViewStream(); //读取最后一个写入位置 this.mLastWriteKey = this.ReadLen(); YunLib.LogWriter.Log("YunMapCacheServer InitCache dbFilePath={0}", Path.GetFullPath(dbFilePath)); YunLib.LogWriter.Log("YunMapCacheServer InitCache mapName={0} Success,WriteLen={1}", mapName, this.mLastWriteKey); Console.WriteLine("YunMapCacheServer InitCache dbFilePath={0}", Path.GetFullPath(dbFilePath)); Console.WriteLine("YunMapCacheServer InitCache mapName={0} Success,WriteLen={1}", mapName, this.mLastWriteKey); } catch (Exception ex) { YunLib.LogWriter.Log(ex.ToString()); } }
/// <summary> /// 彻底清理 /// </summary> public void Destory() { this.Close(); try { var dbFilePath = string.Format("{0}/{1}.dat", YunMapCacheHelper.getMapCacheRoot(), this.mCacheFileName); YunLib.LogWriter.Log("YunMapCacheServer Destory dbFilePath={0} Begin", dbFilePath); if (File.Exists(dbFilePath)) { dbFilePath = Path.GetFullPath(dbFilePath); try { File.Delete(dbFilePath); } catch (Exception eex) { YunLib.LogWriter.Log(eex.Message); } } YunLib.LogWriter.Log("YunMapCacheServer Destory dbFilePath={0} End", dbFilePath); } catch (Exception ex) { YunLib.LogWriter.Log(ex.ToString()); } }
/// <summary> /// 彻底清理 /// </summary> public void Destory() { this.Close(); try { var dbFilePath = string.Format("{0}/{1}.dat", YunMapCacheHelper.getMapCacheRoot(), this.mCacheFileName); if (File.Exists(dbFilePath)) { dbFilePath = Path.GetFullPath(dbFilePath); YunLib.LogWriter.Log("YunMapCacheClient Destory dbFilePath={0}", dbFilePath); File.Delete(dbFilePath); } } catch (Exception) { //YunLib.LogWriter.Log(ex.ToString()); } }
private static void clearOutDateFile(string mLastDateStr) { YunLib.LogWriter.Log("YunMapCacheManager.clearOutDateFile Begin"); string fileDir = YunMapCacheHelper.getMapCacheRoot(); try { var fileList = Directory.GetFiles(fileDir); foreach (string fileName in fileList) { if (fileName.Contains(mLastDateStr)) { continue; } try { File.Delete(fileName); } catch (Exception eex) { YunLib.LogWriter.Log(eex.Message); } } } catch (Exception ex) { YunLib.LogWriter.Log(ex.ToString()); } YunLib.LogWriter.Log("YunMapCacheManager.clearOutDateFile End"); }