public CleanupManager(ILoggerProvider lp, CustomDiskCache cache, CleanupStrategy cs) { this.cache = cache; this.cs = cs; this.lp = lp; queue = new CleanupQueue(); //Called each request cache.CacheResultReturned += delegate(CustomDiskCache sender, CacheResult r) { if (r.Result == CacheQueryResult.Miss) this.AddedFile(r.RelativePath); //It was either updated or added. else this.BeLazy(); }; //Called when the filesystem changes unexpectedly. cache.Index.FileDisappeared += delegate(string relativePath, string physicalPath) { if (lp.Logger != null) lp.Logger.Warn("File disappeared from the cache unexpectedly - reindexing entire cache. File name: {0}", relativePath); //Stop everything ASAP and start a brand new cleaning run. queue.ReplaceWith(new CleanupWorkItem(CleanupWorkItem.Kind.CleanFolderRecursive, "", cache.PhysicalCachePath)); worker.MayHaveWork(); }; worker = new CleanupWorker(lp, cs,queue,cache); }