/// <summary> /// 启动memcached支持 /// </summary> /// <param name="startup"></param> /// <param name="encoding"></param> /// <param name="memcachedType"></param> /// <param name="servers">服务列表</param> /// <param name="key">IoC容器中的key</param> /// <param name="compressProtocol"></param> /// <returns></returns> public static ApplicationStartup UseMemcached(this ApplicationStartup startup, MemcachedType memcachedType, Encoding encoding, string[] servers, string key = null, ICompressProtocol compressProtocol = null) { if (startup.Items.ContainsKey("UseMemcached" + key)) { return(startup); } var mem = memcachedType == MemcachedType.Text ? MemcachedClient.CreateTextCached(servers, encoding, compressProtocol ?? new GZipCompressProtocol() { }) : MemcachedClient.CreateBinaryCached(servers, encoding, compressProtocol ?? new GZipCompressProtocol() { }); startup.ServiceRegister.RegisterInstance(mem, typeof(ICaching), key); startup.Items["UseMemcached" + key] = "t"; return(startup); }
/// <summary> /// 启动memcached支持 /// </summary> /// <param name="encoding"></param> /// <param name="memcachedType"></param> /// <param name="startup"></param> /// <param name="servers">服务列表</param> /// <param name="key">IoC容器中的key</param> /// <returns></returns> public static ApplicationStartup UseMemcached(this ApplicationStartup startup, MemcachedType memcachedType, Encoding encoding, string[] servers, string key = null) { return(UseMemcached(startup, memcachedType, encoding, servers, key, null)); }