public CustomDiskCacheTest(int subfolders, int totalFiles, bool hashModifiedDate) { char c = System.IO.Path.DirectorySeparatorChar; string folder = System.IO.Path.GetTempPath().TrimEnd(c) + c + System.IO.Path.GetRandomFileName(); cache = new CustomDiskCache(this, folder,subfolders,hashModifiedDate); this.quantity = totalFiles; for (int i = 0; i < quantity;i++){ cache.GetCachedFile(i.ToString(),"test",delegate(Stream s){ s.WriteByte(32); //Just one space },defaultDate, 10); } }
public CustomDiskCacheTest(int subfolders, int totalFiles, bool hashModifiedDate) { char c = System.IO.Path.DirectorySeparatorChar; string folder = System.IO.Path.GetTempPath().TrimEnd(c) + c + System.IO.Path.GetRandomFileName(); cache = new CustomDiskCache(this, folder, subfolders, hashModifiedDate); this.quantity = totalFiles; for (int i = 0; i < quantity; i++) { cache.GetCachedFile(i.ToString(), "test", delegate(Stream s){ s.WriteByte(32); //Just one space }, defaultDate, 10); } }
/// <summary> /// Attempts to start the DiskCache using the current settings. Returns true if successful or if already started. Returns false on a configuration error. /// Called by Install() /// </summary> public bool Start() { if (!IsConfigurationValid()) { return(false); } lock (_startSync) { if (_started) { return(true); } if (!IsConfigurationValid()) { return(false); } //Init the writer. writer = new WebConfigWriter(this, PhysicalCacheDir); if (!AsyncModuleMode) { cache = new CustomDiskCache(this, PhysicalCacheDir, 4096, 1024 * 1024 * 30); } if (AsyncModuleMode) { asyncCache = new AsyncCustomDiskCache(this, PhysicalCacheDir, 4096, 1024 * 1024 * 30); } //Init the cleanup strategy var cleanupStrategy = new CleanupStrategy(); //Default settings if null cleanupStrategy.TargetItemsPerFolder = 50; //Init the cleanup worker cleaner = new CleanupManager(this, AsyncModuleMode ? (ICleanableCache)asyncCache : (ICleanableCache)cache, cleanupStrategy); //If we're running with subfolders, enqueue the cache root for cleanup (after the 5 minute delay) //so we don't eternally 'skip' files in the root or in other unused subfolders (since only 'accessed' subfolders are ever cleaned ). if (cleaner != null) { cleaner.CleanAll(); } //Started successfully _started = true; return(true); } }