public override void BuildCache() { // Do not proceed if there is an error if (Error != null) { return; } // Get the cache manager CacheManager cacheMgr = Project.CacheManager; string path = Path.Combine(Project.GetAssetDirectory(), Filename); using (Image img = Image.FromFile(path)) { // Get Frame Dimension FrameDimension dimension = new FrameDimension(img.FrameDimensionsList[0]); // Cahce frames and their thumbnails for (int i = 0; i < FrameCount; i++) { string frameName = String.Format("{0}/F/{1}", ID, i); string thumbName = String.Format("{0}/C/{1}", ID, i); // Select the frame img.SelectActiveFrame(dimension, i); // Cache the frame using (StreamEx frameTmp = new StreamEx(new MemoryStream())) { img.Save(frameTmp, ImageFormat.Png); frameTmp.Position = 0; cacheMgr.AddEntry(frameName, frameTmp); } // Cache the thumbnail using (StreamEx thumbTemp = new StreamEx(new MemoryStream())) { Image thumb = GetThumbnailEx(img, Project.ThumbnailSize); thumb.Save(thumbTemp, ImageFormat.Png); thumbTemp.Position = 0; cacheMgr.AddEntry(thumbName, thumbTemp); } } } }
static void Main(string[] args) { Random random = new Random(); CustomTimer timer = new CustomTimer(); Console.WriteLine("ICacheManager<int, int>"); for (int j = 0; j < 10; ++j) { ICacheManager<int, int> cacheManager = new CacheManager<int, int>(); timer.Start(); // No concurrency insertions for (int i = 0; i < 1000000; ++i) { cacheManager.AddEntry(random.Next(int.MaxValue), i); } timer.StopAndReport(); GC.Collect(2); GC.WaitForFullGCComplete(); } Console.WriteLine(""); Console.WriteLine("ICacheManager<int, string>"); for (int j = 0; j < 10; ++j) { ICacheManager<int, string> cacheManager = new CacheManager<int, string>(); timer.Start(); // No concurrency insertions for (int i = 0; i < 1000000; ++i) { cacheManager.AddEntry(random.Next(int.MaxValue), "dummy string " + i); } timer.StopAndReport(); GC.Collect(2); GC.WaitForFullGCComplete(); } Console.WriteLine(""); Console.WriteLine("ICacheManager<int, string, int>"); for (int j = 0; j < 10; ++j) { ICacheManager<int, string, int> cacheManager = new CacheManager<int, string, int>(); timer.Start(); // No concurrency insertions for (int i = 0; i < 1000000; ++i) { cacheManager.AddEntry(random.Next(int.MaxValue), "dummy string " + i); } timer.StopAndReport(); GC.Collect(2); GC.WaitForFullGCComplete(); } Console.WriteLine(""); Console.ReadLine(); }