public virtual Task TestHintPropagation()
        {
            AsyncOut <WrapperCacheSession> wrapperSessionBox = new AsyncOut <WrapperCacheSession>();
            var cacheId = Guid.NewGuid().ToString("N");

            return(MemoizationStoreAdapterCache.WrapCacheForTestAsync(
                       cacheId,
                       session => (wrapperSessionBox.Value = new WrapperCacheSession(this, session)),
                       () =>
            {
                try
                {
                    ConfigureRealCache(cacheId);

                    BeforeRebuild("Build #1");

                    var wrapperSession = wrapperSessionBox.Value;
                    var registerContentCacheEntries = wrapperSession.AddedContentHashLists.Where(e => e.Value.urgencyHint == UrgencyHint.RegisterAssociatedContent).ToArray();
                    Assert.Equal(TotalPips, registerContentCacheEntries.Length);

                    foreach (var entry in registerContentCacheEntries)
                    {
                        wrapperSession.EnsureUrgencyHint(entry.Key.Selector.ContentHash, UrgencyHint.SkipRegisterContent);
                        wrapperSession.EnsureUrgencyHint(entry.Value.contentHashList.ContentHashList.Hashes, UrgencyHint.SkipRegisterContent);
                    }

                    return BoolTask.True;
                }
                finally
                {
                    DisposeRealCache();
                }
            }));
        }
        /// <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 distributedCache = CreateDistributedCache(logger, cacheConfig);
                logger.Debug($"Distributed cache created successfully.");

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

                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));
            }
        }
예제 #3
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));
            }
        }