Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates and starts a thread that consumes the queue, pausing until notified when 'queue' empties.
 /// </summary>
 /// <param name="cs"></param>
 /// <param name="queue"></param>
 /// <param name="cache"></param>
 public CleanupWorker(ILoggerProvider lp, CleanupStrategy cs, CleanupQueue queue, CustomDiskCache cache) : base("DiskCache-CleanupWorker")
 {
     this.cs        = cs;
     this.queue     = queue;
     this.cache     = cache;
     this.lp        = lp;
     t              = new Thread(main);
     t.IsBackground = true;
     t.Start();
 }