/// <summary> /// 拆分内存序列化为本地文件 /// </summary> public static void SerializeSplitCache(Dictionary <int, T> dic, string bufferName) { int count = dic.Values.Count / 5; var buffer1 = SplitCache(dic, 0, count); var buffer2 = SplitCache(dic, count, count); var buffer3 = SplitCache(dic, count * 2, count); var buffer4 = SplitCache(dic, count * 3, count); var lastcount = dic.Values.Count - count * 4; var buffer5 = SplitCache(dic, count * 4, lastcount); //var buffer1 = list.Take(count).ToList(); //var buffer2 = list.Skip(count).Take(count).ToList(); //var buffer3 = list.Skip(count * 2).Take(count).ToList(); //var buffer4 = list.Skip(count * 3).Take(count).ToList(); //var buffer5 = list.Skip(count * 4).ToList(); SerizlizerUtils <T[]> .SerializeLastCache(buffer1, string.Format("{0}1", bufferName)); SerizlizerUtils <T[]> .SerializeLastCache(buffer2, string.Format("{0}2", bufferName)); SerizlizerUtils <T[]> .SerializeLastCache(buffer3, string.Format("{0}3", bufferName)); SerizlizerUtils <T[]> .SerializeLastCache(buffer4, string.Format("{0}4", bufferName)); SerizlizerUtils <T[]> .SerializeLastCache(buffer5, string.Format("{0}5", bufferName)); }
public static void SerializeSplitCache(List <T> list, string bufferName) { int count = list.Count / 5; var buffer1 = new T[count]; list.CopyTo(0, buffer1, 0, count); var buffer2 = new T[count]; list.CopyTo(count, buffer2, 0, count); var buffer3 = new T[count]; list.CopyTo(count * 2, buffer3, 0, count); var buffer4 = new T[count]; list.CopyTo(count * 3, buffer4, 0, count); var lastcount = list.Count - count * 4; var buffer5 = new T[lastcount]; list.CopyTo(count * 4, buffer5, 0, lastcount); SerizlizerUtils <T[]> .SerializeLastCache(buffer1, string.Format("{0}1", bufferName)); SerizlizerUtils <T[]> .SerializeLastCache(buffer2, string.Format("{0}2", bufferName)); SerizlizerUtils <T[]> .SerializeLastCache(buffer3, string.Format("{0}3", bufferName)); SerizlizerUtils <T[]> .SerializeLastCache(buffer4, string.Format("{0}4", bufferName)); SerizlizerUtils <T[]> .SerializeLastCache(buffer5, string.Format("{0}5", bufferName)); }
/// <summary> /// 反序列化本地拆分文件为内存 /// </summary> public static List <T> DeserializeSplitCache(string bufferName) { var buffer1 = SerizlizerUtils <T[]> .DeserializeLastCache(string.Format("{0}1", bufferName)); var buffer2 = SerizlizerUtils <T[]> .DeserializeLastCache(string.Format("{0}2", bufferName)); var buffer3 = SerizlizerUtils <T[]> .DeserializeLastCache(string.Format("{0}3", bufferName)); var buffer4 = SerizlizerUtils <T[]> .DeserializeLastCache(string.Format("{0}4", bufferName)); var buffer5 = SerizlizerUtils <T[]> .DeserializeLastCache(string.Format("{0}5", bufferName)); if (buffer1 != null) { var list = new List <T>(buffer1.Length + buffer2.Length + buffer3.Length + buffer4.Length + buffer5.Length); list.AddRange(buffer1); list.AddRange(buffer2); list.AddRange(buffer3); list.AddRange(buffer4); list.AddRange(buffer5); return(list); } return(null); }