62,046
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using Memcached.ClientLibrary;
using BillBlog.Config;
using System.Collections;
/// <summary>
/// Memcached缓存
/// </summary>
public class MemcachedCache
{
private MemcachedClient client;
public MemcachedCache()
{
SockIOPool pool = SockIOPool.GetInstance();
string[] strSvrs = { "172.16.100.230" };
//List<string> listServers =
//CacheConfigs.GetConfig().MemcachedServers;
pool.SetServers(strSvrs);
pool.MinConnections = 3;
pool.MaxConnections = 5;
pool.InitConnections = 3;
pool.SocketConnectTimeout = 5000;
pool.MaintenanceSleep = 30;
pool.Failover = true;
pool.Nagle = false;
pool.Initialize();
this.client = new MemcachedClient();
client.EnableCompression = false;
}
public bool Add<T>(string key, T value, TimeSpan duration)
{
//if (duration <= TimeSpan.Zero)
//{
// duration = this.MaxDuration;
//}
DateTime dt = DateTime.Now.AddMinutes(duration.Minutes);
return client.Add(key, value, dt);
}
}