コード例 #1
0
        public OcelotEasyCachingCache(
            IOptions <OcelotEasyCachingOptions> optionsAccs,
            IEasyCachingProviderFactory providerFactory,
            IHybridProviderFactory hybridFactory = null)
        {
            _options = optionsAccs.Value;

            if (!_options.EnableHybrid)
            {
                _provider = providerFactory.GetCachingProvider(_options.ProviderName);
            }
            else
            {
                _hybridProvider = hybridFactory.GetHybridCachingProvider(_options.HybridName);
            }
        }
コード例 #2
0
        public static IOcelotBuilder AddEasyCaching(this IOcelotBuilder builder, Action <OcelotEasyCachingOptions> setupAction)
        {
            builder.Services.RemoveAll(typeof(IOcelotCache <CachedResponse>));
            builder.Services.RemoveAll(typeof(IOcelotCache <IInternalConfiguration>));
            builder.Services.RemoveAll(typeof(IOcelotCache <FileConfiguration>));

            var options = new OcelotEasyCachingOptions();

            setupAction(options);
            builder.Services.Configure(setupAction);
            builder.Services.AddEasyCaching(options.Settings);

            builder.Services.AddSingleton(typeof(IOcelotCache <>), typeof(OcelotEasyCachingCache <>));

            builder.Services.RemoveAll(typeof(ICacheKeyGenerator));
            builder.Services.AddSingleton <ICacheKeyGenerator, CacheKeyGenerator>();

            return(builder);
        }