Beispiel #1
0
        /// <summary>
        /// LocalCacheStrategy的构造函数
        /// </summary>
        MemcachedObjectCacheStrategy(/*ILoggerFactory loggerFactory, IOptions<MemcachedClientOptions> optionsAccessor*/)
        {
            _config = GetMemcachedClientConfiguration();
#if NET45 //|| NET461
            Cache = new MemcachedClient(_config);
#else
            var            provider      = SenparcDI.GetIServiceProvider();
            ILoggerFactory loggerFactory = provider.GetService <ILoggerFactory>();
            Cache = new MemcachedClient(loggerFactory, _config);
#endif
        }
Beispiel #2
0
        private static MemcachedClientConfiguration GetMemcachedClientConfiguration(/*ILoggerFactory loggerFactory, IOptions<MemcachedClientOptions> optionsAccessor*/)
#endif
        {
            //每次都要新建

#if NET45
            var config = new MemcachedClientConfiguration();
            foreach (var server in _serverlist)
            {
                config.Servers.Add(new IPEndPoint(IPAddress.Parse(server.Key), server.Value));
            }
            config.Protocol = MemcachedProtocol.Binary;
#else
            var            provider      = SenparcDI.GetIServiceProvider();
            ILoggerFactory loggerFactory = provider.GetService <ILoggerFactory>();
            IOptions <MemcachedClientOptions> optionsAccessor = provider.GetService <IOptions <MemcachedClientOptions> >();

            var config = new MemcachedClientConfiguration(loggerFactory, optionsAccessor);
#endif
            return(config);
        }