单例设计模式
来源:互联网 发布:win7 php环境搭建 编辑:程序博客网 时间:2024/06/06 16:37
using Memcached.ClientLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZY.Common
{
public static class CacheHelper
{
//单例模式
{
string[] servers = { "192.168.1.100:11211" };
//初始化池
SockIOPool pool = SockIOPool.GetInstance();
pool.SetServers(servers);
pool.InitConnections = 3;
pool.MinConnections = 3;
pool.MaxConnections = 5;
pool.SocketConnectTimeout = 1000;
pool.SocketTimeout = 3000;
pool.MaintenanceSleep = 30;
pool.Failover = true;
pool.Nagle = false;
pool.Initialize();
MemcachedClient mc = new Memcached.ClientLibrary.MemcachedClient();
mc.EnableCompression = false;
}
public static void Add(string key, object value, DateTime ExpireDate)
{
if (mc.KeyExists(key))
{
mc.Set(key, value, ExpireDate);
}
else
{
mc.Add(key, value, ExpireDate);
}
}
public static object Set(string key)
{
return mc.Get(key);
}
public static void Add<T>(string key, T value, DateTime ExpireDate)
{
Add(key, value, ExpireDate);
}
public static T Get<T>(string key) where T : class
{
return mc.Get(key) as T;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZY.Common
{
public static class CacheHelper
{
//单例模式
public static readonly Memcached.ClientLibrary.MemcachedClient mc;
{
string[] servers = { "192.168.1.100:11211" };
//初始化池
SockIOPool pool = SockIOPool.GetInstance();
pool.SetServers(servers);
pool.InitConnections = 3;
pool.MinConnections = 3;
pool.MaxConnections = 5;
pool.SocketConnectTimeout = 1000;
pool.SocketTimeout = 3000;
pool.MaintenanceSleep = 30;
pool.Failover = true;
pool.Nagle = false;
pool.Initialize();
MemcachedClient mc = new Memcached.ClientLibrary.MemcachedClient();
mc.EnableCompression = false;
}
public static void Add(string key, object value, DateTime ExpireDate)
{
if (mc.KeyExists(key))
{
mc.Set(key, value, ExpireDate);
}
else
{
mc.Add(key, value, ExpireDate);
}
}
public static object Set(string key)
{
return mc.Get(key);
}
public static void Add<T>(string key, T value, DateTime ExpireDate)
{
Add(key, value, ExpireDate);
}
public static T Get<T>(string key) where T : class
{
return mc.Get(key) as T;
}
}
}
0 0
- 设计模式--单例
- 单例设计模式
- 设计模式----单例
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 设计模式-单例
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- Linux下OpenVPN比较详细安装
- Maven本地私有仓库搭建
- iOS 添加粘贴板的功能(复制功能)
- 微服务的额外代价
- Emgu的Image(Of Gray,Byte)转OpenCV的IplImage
- 单例设计模式
- NSIS 文本函数头文件介绍(一)
- 原来的文章都没有了
- C++ 内存管理
- Mysql事务提交方式
- n*n阶矩阵逆时针输出
- 【云快讯】《“云计算”也要防雷,20%数据中心故障和雷击有关》
- maven 修改使用jdk版本
- Mysql实现full join的替换方法