コード例 #1
0
        public MemcachedCache()
        {
            foreach (string info in (WebConfig.GetApp("MemcachedCache.MemcachedServer") ?? string.Empty).Split(';'))
            {
                if (!string.IsNullOrEmpty(info.Trim()))
                {
                    memcachedServer.Add(info);
                }
            }

            if (pool.IsNull() && memcachedServer.Count > 0)
            {
                pool = SockIOPool.GetInstance();
                pool.SetServers(memcachedServer);

                pool.InitConnections      = Convert.ToInt32(WebConfig.GetApp("MemcachedCache.InitConnections") ?? "3");
                pool.MinConnections       = Convert.ToInt32(WebConfig.GetApp("MemcachedCache.MinConnections") ?? "3");
                pool.MaxConnections       = Convert.ToInt32(WebConfig.GetApp("MemcachedCache.MaxConnections") ?? "5");
                pool.SocketConnectTimeout = Convert.ToInt32(WebConfig.GetApp("MemcachedCache.SocketConnectTimeout") ?? "1000");
                pool.SocketTimeout        = Convert.ToInt32(WebConfig.GetApp("MemcachedCache.SocketTimeout") ?? "3000");
                pool.MaintenanceSleep     = Convert.ToInt32(WebConfig.GetApp("MemcachedCache.MaintenanceSleep") ?? "30");
                pool.Failover             = (WebConfig.GetApp("MemcachedCache.Failover") ?? "") == "true" ? true : false;
                pool.Nagle = (WebConfig.GetApp("MemcachedCache.Nagle") ?? "") == "true" ? true : false;
                //pool.HashingAlgorithm = HashingAlgorithm.NewCompatibleHash;
                pool.Initialize();

                mc                   = new MemcachedClient();
                mc.PoolName          = WebConfig.GetApp("MemcachedCache.PoolName") ?? "default";
                mc.EnableCompression = (WebConfig.GetApp("MemcachedCache.EnableCompression") ?? "") == "true" ? true : false;
            }
        }