Beispiel #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));
        }
        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));
        }
Beispiel #3
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;
        }
        private async Task RunTest(MockRedisDatabase redisDb, Func <Context, IMetadataCache, MockRedisDatabase, Task> test)
        {
            var context = new Context(TestGlobal.Logger);

            RedisConnectionMultiplexer.TestConnectionMultiplexer = MockRedisDatabaseFactory.CreateConnection(redisDb);
            var tracer        = new DistributedCacheSessionTracer(TestGlobal.Logger, nameof(MemoryMetadataCacheTests));
            var metadataCache = new RedisMetadataCache(new EnvironmentConnectionStringProvider(string.Empty), new RedisSerializer(), RedisNameSpace, tracer);
            await metadataCache.StartupAsync(context).ShouldBeSuccess();

            await test(context, metadataCache, redisDb);

            await metadataCache.ShutdownAsync(context).ShouldBeSuccess();
        }