示例#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));
        }
示例#2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="DistributedCache" /> class.
        /// </summary>
        public DistributedCache(ILogger logger, ICache innerICache, IMetadataCache metadataCache, DistributedCacheSessionTracer cacheTracer, ReadThroughMode readThroughMode)
        {
            Contract.Requires(logger != null);
            Contract.Requires(innerICache != null);
            Contract.Requires(metadataCache != null);

            _logger        = logger;
            _innerICache   = innerICache;
            _metadataCache = metadataCache;

            _tracer          = cacheTracer;
            _readThroughMode = readThroughMode;
        }
示例#3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="DistributedCacheSession" /> class.
        /// </summary>
        public DistributedCacheSession(
            ILogger logger,
            string name,
            ICacheSession innerCacheSession,
            Guid innerCacheId,
            IMetadataCache metadataCache,
            DistributedCacheSessionTracer tracer,
            ReadThroughMode readThroughModeMode)
            : base(logger, name, innerCacheSession, innerCacheId, metadataCache, tracer, readThroughModeMode)
        {
            Contract.Requires(logger != null);
            Contract.Requires(innerCacheSession != null);
            Contract.Requires(metadataCache != null);

            _innerCacheSession = innerCacheSession;
        }
示例#4
0
        private ICache CreateCache(
            DisposableDirectory testDirectory,
            string cacheNamespace,
            IAbsFileSystem fileSystem,
            ILogger logger,
            BackingOption backingOption,
            StorageOption storageOption,
            TimeSpan?expiryMinimum,
            TimeSpan?expiryRange,
            ReadThroughMode readThroughMode)
        {
            var innerCache = base.CreateCache(testDirectory, cacheNamespace, fileSystem, logger, backingOption, storageOption, expiryMinimum, expiryRange);

            return(TestDistributedCacheFactory.CreateCache(
                       logger, innerCache, cacheNamespace, nameof(ReadThroughDistributedWriteBehindBuildCacheSimulationTests), readThroughMode));
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ReadOnlyDistributedCacheSession" /> class.
        /// </summary>
        public ReadOnlyDistributedCacheSession(
            ILogger logger,
            string name,
            IReadOnlyCacheSession innerCacheSession,
            Guid innerCacheId,
            IMetadataCache metadataCache,
            DistributedCacheSessionTracer tracer,
            ReadThroughMode readThroughModeMode)
        {
            Contract.Requires(logger != null);
            Contract.Requires(innerCacheSession != null);
            Contract.Requires(metadataCache != null);

            Logger             = logger;
            Name               = name;
            MetadataCache      = metadataCache;
            _innerCacheSession = innerCacheSession;
            _innerCacheId      = innerCacheId;
            DistributedTracer  = tracer;
            _readThroughMode   = readThroughModeMode;
        }
        internal static ICache CreateCache(
            ILogger logger, ICache innerCache, string redisNamespace, string testClassName, ReadThroughMode readThroughMode)
        {
            var redisDb = RedisDatabases.GetOrAdd(redisNamespace, _ => new MockRedisDatabase(SystemClock.Instance));

            RedisConnectionMultiplexer.TestConnectionMultiplexer = MockRedisDatabaseFactory.CreateConnection(redisDb);
            var tracer        = new DistributedCacheSessionTracer(TestGlobal.Logger, testClassName);
            var metadataCache = new RedisMetadataCache(
                new EnvironmentConnectionStringProvider(string.Empty), new RedisSerializer(), redisNamespace, tracer);

            return(new DistributedCache(logger, innerCache, metadataCache, tracer, readThroughMode));
        }