Enyim.Caching 客户端配置及示例
一、工作准备
memcached客户端:Enyim.Caching.2.13
memcached服务器:memcached-win64-1.4.4-14
备注:不建议使用windows服务器,开发环境可以玩玩
二、Enyim.Caching配置
<configSections> <sectionGroup name="enyim.com"> <section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching" /> </sectionGroup> </configSections> <enyim.com> <!--memcached在windows下不支持二进制协议,必须使用Text;Linux下可使用Binary--> <memcached protocol="Text"> <servers> <add address="192.168.1.101" port="11211" /> </servers> <socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:01:10" deadTimeout="00:02:00" /> </memcached> </enyim.com>
三、后台代码简单实现
private static Enyim.Caching.MemcachedClient mc = new Enyim.Caching.MemcachedClient(); public ActionResult Memcached() { return View(); } public ActionResult SetMemcached(string key, string value) { var result = mc.Store(Enyim.Caching.Memcached.StoreMode.Set, key, value); return JRCommonHandleResult(result); } public ActionResult GetMemcached(string key) { var content = mc.Get<string>(key); return JRSuccess(content); }