public FileSystemOutputCacheBackgroundTask(
            IAppDataFolder appDataFolder,
            ShellSettings shellSettings,
            ICacheManager cacheManager,
            IClock clock,
            ISignals signals)
        {
            _appDataFolder = appDataFolder;
            _shellSettings = shellSettings;
            _cacheManager  = cacheManager;
            _clock         = clock;
            _signals       = signals;

            _metadata = FileSystemOutputCacheStorageProvider.GetMetadataPath(appDataFolder, _shellSettings.Name);
            _content  = FileSystemOutputCacheStorageProvider.GetContentPath(appDataFolder, _shellSettings.Name);
        }
예제 #2
0
        public void Sweep()
        {
            foreach (var filename in _appDataFolder.ListFiles(_root).ToArray())
            {
                var validUntilUtc = _cacheManager.Get(filename, context => {
                    _signals.When(filename);

                    using (var stream = _appDataFolder.OpenFile(filename)) {
                        var cacheItem = FileSystemOutputCacheStorageProvider.Deserialize(stream);
                        return(cacheItem.ValidUntilUtc);
                    }
                });

                if (_clock.UtcNow > validUntilUtc)
                {
                    _appDataFolder.DeleteFile(filename);
                    _signals.Trigger(filename);
                }
            }
        }
        public void Sweep()
        {
            foreach (var filename in _appDataFolder.ListFiles(_metadata).ToArray())
            {
                var hash = Path.GetFileName(filename);

                var validUntilUtc = _cacheManager.Get(hash, context => {
                    _signals.When(hash);

                    using (var stream = _appDataFolder.OpenFile(filename)) {
                        var cacheItem = FileSystemOutputCacheStorageProvider.DeserializeMetadata(stream);
                        return(cacheItem.ValidUntilUtc);
                    }
                });

                if (_clock.UtcNow > validUntilUtc)
                {
                    _appDataFolder.DeleteFile(_appDataFolder.Combine(_metadata, hash));
                    _appDataFolder.DeleteFile(_appDataFolder.Combine(_content, hash));
                    _signals.Trigger(filename);
                }
            }
        }