/// <summary>
        /// 自定义缓存策略
        /// </summary>
        private void RegisterWeixinCache()
        {
            //如果留空,默认为localhost(默认端口)

            #region  Redis配置
            var redisConfiguration = System.Configuration.ConfigurationManager.AppSettings["Cache_Redis_Configuration"];
            RedisManager.ConfigurationOption = redisConfiguration;

            //如果不执行下面的注册过程,则默认使用本地缓存

            if (!string.IsNullOrEmpty(redisConfiguration) && redisConfiguration != "Redis配置")
            {
                CacheStrategyFactory.RegisterObjectCacheStrategy(() => RedisObjectCacheStrategy.Instance);//Redis
            }

            #endregion

            #region Memcached 配置

            var memcachedConfig = new Dictionary <string, int>()
            {
                { "localhost", 9101 }
            };
            MemcachedObjectCacheStrategy.RegisterServerList(memcachedConfig);


            #endregion

            //CacheStrategyFactory.RegisterContainerCacheStrategy(() => MemcachedContainerStrategy.Instance);//Memcached
        }
示例#2
0
        /// <summary>
        /// 自定义缓存策略
        /// </summary>
        private void RegisterWeixinCache()
        {
            // 当同一个分布式缓存同时服务于多个网站(应用程序池)时,可以使用命名空间将其隔离(非必须)
            Config.DefaultCacheNamespace = "DefaultWeixinCache";

            #region  Redis配置
            //如果留空,默认为localhost(默认端口)
            var redisConfiguration = System.Configuration.ConfigurationManager.AppSettings["Cache_Redis_Configuration"];
            RedisManager.ConfigurationOption = redisConfiguration;

            //如果不执行下面的注册过程,则默认使用本地缓存

            if (!string.IsNullOrEmpty(redisConfiguration) && redisConfiguration != "Redis配置")
            {
                CacheStrategyFactory.RegisterObjectCacheStrategy(() => RedisObjectCacheStrategy.Instance);//Redis
            }

            #endregion

            #region Memcached 配置

            var memcachedConfig = new Dictionary <string, int>()
            {
                { "localhost", 9101 }
            };
            MemcachedObjectCacheStrategy.RegisterServerList(memcachedConfig);


            #endregion
        }
示例#3
0
        public void RegisterServerListTest()
        {
            var str = "localhost:12211;localhost:12345";

            MemcachedObjectCacheStrategy.RegisterServerList(str);

            //由于是private方法,这里只能确认是否有异常,或者进行读写测试
        }
示例#4
0
        /// <summary>
        /// 注册 Memcached 缓存信息
        /// </summary>
        /// <param name="registerService">RegisterService</param>
        /// <param name="memcachedConfig">memcached连接字符串列表</param>
        /// <param name="memcachedObjectCacheStrategyInstance">缓存策略的委托,第一个参数为 memcachedConfig</param>
        /// <returns></returns>
        public static IRegisterService RegisterCacheMemcached(this IRegisterService registerService,
                                                              Dictionary <string, int> memcachedConfig,
                                                              Func <Dictionary <string, int>, IObjectCacheStrategy> memcachedObjectCacheStrategyInstance)
        {
            MemcachedObjectCacheStrategy.RegisterServerList(memcachedConfig);

            //此处先执行一次委托,直接在下方注册结果,提高每次调用的执行效率
            IObjectCacheStrategy objectCacheStrategy = memcachedObjectCacheStrategyInstance(memcachedConfig);

            if (objectCacheStrategy != null)
            {
                CacheStrategyFactory.RegisterObjectCacheStrategy(() => objectCacheStrategy);//Memcached
            }

            return(registerService);
        }