Example #1
0
        public void Insert(object value, string key, CachePeriod cachePeriod)
        {
            try
            {
                string fileName = CacheDirectory + "//" +
                                  key +
                                  cachePeriod.GetKey() +
                                  " " +
                                  cachePeriod.ToExpirationDateString();

                if (value is IList list && list.Count > ChunkSize)
                {
                    var tempList = new List <object>();
                    foreach (var t in list)
                    {
                        tempList.Add(t);
                    }

                    var counter = 0;
                    while (tempList.Count > 0)
                    {
                        counter++;
                        var chunk = new List <object>();

                        for (int i = 0; i < tempList.Count; i++)
                        {
                            if (i >= ChunkSize)
                            {
                                break;
                            }

                            var item = tempList[i];
                            chunk.Add(item);
                        }

                        foreach (var item in chunk)
                        {
                            tempList.Remove(item);
                        }


                        File.WriteAllText(fileName + FileExtension + counter, chunk.ToJson());
                    }
                }
                else
                {
                    File.WriteAllText(fileName + FileExtension, value.ToJson());
                }
            }