Memcached client main class. Use the static methods Setup and GetInstance to setup and get an instance of the client for use.
Exemple #1
0
        //ip:poart
        void InitMemCache(string host)
        {
            //以下代码,要以具体使用的 Memcached Client 来处理
            //
            string[] servers = { host };

            //缓存服务设置,配置优先级高,无配置使用默认值

            if (!MemcachedClient.Exists(host)) {
                MemcachedClient.Setup(host, servers);
            }

            //实例化
            _cache = MemcachedClient.GetInstance(host);

            //检查缓存服务是否开启

            _cache.SendReceiveTimeout = 1000;
            _cache.MinPoolSize = 10;
            _cache.MaxPoolSize = 100;
        }
Exemple #2
0
 /// <summary>
 /// Static method for creating an instance. This method will throw an exception if the name already exists.
 /// </summary>
 /// <param name="name">The name of the instance.</param>
 /// <param name="servers">A list of memcached servers in standard notation: host:port. 
 /// If port is omitted, the default value of 11211 is used. 
 /// Both IP addresses and host names are accepted, for example:
 /// "localhost", "127.0.0.1", "cache01.example.com:12345", "127.0.0.1:12345", etc.</param>
 public static void Setup(string name, string[] servers)
 {
     if (instances.ContainsKey(name)) {
         throw new ConfigurationErrorsException("Trying to configure MemcachedClient instance \"" + name + "\" twice.");
     }
     instances[name] = new MemcachedClient(name, servers);
 }
Exemple #3
0
 public static MemcachedClient GetInstance()
 {
     return defaultInstance ?? (defaultInstance = GetInstance("default"));
 }