コード例 #1
0
        public CleanupManager(ILogger logger, ICleanableCache cache, CleanupStrategy cs)
        {
            this.cache  = cache;
            this.cs     = cs;
            this.logger = logger;
            queue       = new CleanupQueue();
            //Called each request
            cache.CacheResultReturned += delegate(ICleanableCache sender, CacheResult r) {
                if (r.Result == CacheQueryResult.Miss)
                {
                    this.AddedFile(r.RelativePath); //It was either updated or added.
                }
                else
                {
                    this.BeLazy();
                }
            };
            //Called when the file system changes unexpectedly.
            cache.Index.FileDisappeared += delegate(string relativePath, string physicalPath) {
                logger?.LogWarning("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(this.logger, cs, queue, cache);
        }
コード例 #2
0
 /// <summary>
 /// Creates and starts a thread that consumes the queue, pausing until notified when 'queue' empties.
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="cs"></param>
 /// <param name="queue"></param>
 /// <param name="cache"></param>
 public CleanupWorker(ILogger logger, CleanupStrategy cs, CleanupQueue queue, ICleanableCache cache) : base("DiskCache-CleanupWorker")
 {
     this.cs     = cs;
     this.queue  = queue;
     this.cache  = cache;
     this.logger = logger;
     t           = new Thread(main)
     {
         IsBackground = true
     };
     t.Start();
 }