Exemplo n.º 1
0
        private static BuildXL.Cache.MemoizationStore.Interfaces.Caches.ICache CreateDistributedCache(ILogger logger, Config cacheConfig)
        {
            int cacheKeyBumpTimeMins = cacheConfig.CacheKeyBumpTimeMins;

            if (cacheKeyBumpTimeMins <= 0)
            {
                logger.Debug("Config specified bump time in minutes is invalid {0}. Using default bump time {1}", cacheKeyBumpTimeMins, Config.DefaultCacheKeyBumpTimeMins);
                cacheKeyBumpTimeMins = Config.DefaultCacheKeyBumpTimeMins;
            }

            TimeSpan keyBump = TimeSpan.FromMinutes(cacheKeyBumpTimeMins);

            var metadataTracer = new DistributedCacheSessionTracer(logger, nameof(DistributedCache));

            string metadataKeyspace = cacheConfig.CacheNamespace;

            if (string.IsNullOrWhiteSpace(metadataKeyspace))
            {
                metadataKeyspace = DefaultMetadataKeyspace;
            }

            IMetadataCache metadataCache = RedisMetadataCacheFactory.Create(metadataTracer, keySpace: metadataKeyspace, cacheKeyBumpTime: keyBump);

            var innerCache = cacheConfig.DisableContent
                ?  new OneLevelCache(
                contentStoreFunc: () => new ReadOnlyEmptyContentStore(),
                memoizationStoreFunc: () => (BuildCacheCache)BuildCacheUtils.CreateBuildCacheCache(cacheConfig, logger, Environment.GetEnvironmentVariable("VSTSPERSONALACCESSTOKEN")),
                id: Guid.NewGuid(),
                passContentToMemoization: false)
                : BuildCacheUtils.CreateBuildCacheCache(cacheConfig, logger, Environment.GetEnvironmentVariable("VSTSPERSONALACCESSTOKEN"));

            ReadThroughMode readThroughMode = cacheConfig.SealUnbackedContentHashLists ? ReadThroughMode.ReadThrough : ReadThroughMode.None;

            return(new DistributedCache(logger, innerCache, metadataCache, metadataTracer, readThroughMode));
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public async Task <Possible <ICache, Failure> > InitializeCacheAsync(ICacheConfigData cacheData, Guid activityId, ICacheConfiguration cacheConfiguration = null)
        {
            Contract.Requires(cacheData != null);

            var possibleCacheConfig = cacheData.Create <Config>();

            if (!possibleCacheConfig.Succeeded)
            {
                return(possibleCacheConfig.Failure);
            }

            Config cacheConfig = possibleCacheConfig.Result;

            try
            {
                var logPath = new AbsolutePath(cacheConfig.CacheLogPath);
                var logger  = new DisposeLogger(() => new EtwFileLog(logPath.Path, cacheConfig.CacheId), cacheConfig.LogFlushIntervalSeconds);

                var vstsCache = BuildCacheUtils.CreateBuildCacheCache(cacheConfig, logger, Environment.GetEnvironmentVariable("VSTSPERSONALACCESSTOKEN"));

                var statsFilePath = new AbsolutePath(logPath.Path + ".stats");
                var cache         = new MemoizationStoreAdapterCache(cacheConfig.CacheId, vstsCache, logger, statsFilePath);

                logger.Diagnostic($"Initializing the cache [{cacheConfig.CacheId}]");
                var startupResult = await cache.StartupAsync();

                if (!startupResult.Succeeded)
                {
                    logger.Error($"Error while initializing the cache [{cacheConfig.CacheId}]. Failure: {startupResult.Failure}");
                    cache.Dispose();

                    return(startupResult.Failure);
                }

                return(cache);
            }
            catch (Exception e)
            {
                return(new CacheConstructionFailure(cacheConfig.CacheId, e));
            }
        }