0
点赞
收藏
分享

微信扫一扫

memcached 相关资源汇总


Memcached官方站点:​​http://www.danga.com/memcached​​/

Memcached Win32 1.2.6下载:​​http://code.jellycan.com/memcached/​​

安装帮助:​​Windows下的.NET+ Memcached安装​​

Memcached .NET客户端:

1).NET memcached client library

  下载地址:​​https://sourceforge.net/projects/memcacheddotnet​​

  相关文章:​​分布式缓存系统Memcached简介与实践​​

2)enyim.com Memcached Client

  下载地址:​​http://www.codeplex.com/EnyimMemcached/​​

  相关文章:​​memcached系列2:memcached实例​​  

3)Memcached Providers

  下载地址:​​http://www.codeplex.com/memcachedproviders​​

  相关文章:​​.NET平台上的Memcached客户端介绍​​

4) BeIT Memcached

  下载地址:​​http://code.google.com/p/beitmemcached/​​

  相关文章:​​分布式缓存BeIT Memcached简介​​


相关链接: 

a)

​​ Memcached for Windows ​​


b)

​​ Which .NET Memcached client do you use, EnyimMemcached vs. BeITMemcached?​​


c)

​​博客园知识库Memcached相关文章​





NorthScale Memcached Server官方推荐的.NET客户端是EnyimMemcached。EnyimMemcached有两种方式可以访问NorthScale Memcached Server:

1) Enyim.Caching.MemcachedClient(Enyim.Caching.dll);

2) NorthScale.Store.NorthScaleClient(Northscale.Store.dll)。NorthScaleClient是基于Enyim.Caching针对NorthScale Memcached Server专门开发的客户端。

这两个客户端的主要区别在于:

1)Enyim.Caching.MemcachedClientt只能访问NorthScale Memcached Server的默认Bucket(默认访问服务器11211端口);

2)NorthScale.Store.NorthScaleClient只能访问NorthScale Memcached Server(默认访问服务器8080端口)。

这里主要讲一下NorthScaleClient的使用方法:

1. 下载NorthScaleClient,下载地址:​​http://github.com/enyim/EnyimMemcached/downloads​​。

2. 在项目中添加对Northscale.Store.dll的引用。

3. 在web.config中添加相应的配置:

  a) 在configSections中添加下面的配置:



<section name="northscale" type="NorthScale.Store.Configuration.NorthScaleClientSection, NorthScale.Store" />



  b) 在configuration中添加如下的配置:



<northscale>
<servers>
<add uri="http://localhost:8080/pools/default" />
<add uri="http://localhost:8080/pools/default" />
</servers>
<socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:00:10" deadTimeout="00:02:00"/>
</northscale>



  注:如果只有一台Memcached服务器,要在这里填两个相同的uri,不然调用时会报错。

4. 客户端调用示例代码:



public class EnyimMemcachedProvider : ICacheProvider
{
private static NorthScaleClient client;

static EnyimMemcachedProvider()
{
try
{
client = new NorthScaleClient();
}
catch (Exception ex)
{
log4net.LogManager.GetLogger("cnblogs").Info("EnyimMemcachedProvider", ex);
}
}

#region ICacheProvider Members

public void Add(string key, object value)
{
if (client != null)
{
client.Store(StoreMode.Set, key, value);
}
}

public void Add(string key, object value, int cacheSecond)
{
if (client != null)
{
client.Store(StoreMode.Set, key, value, new TimeSpan(0, 0, cacheSecond));
}
}

public object GetData(string key)
{
if (client == null)
{
return null;
}
return client.Get(key);
}

public void Remove(string key)
{
if (client != null)
{
client.Remove(key);
}
}

#endregion
}



需要注意的地方:

1) 由于创建一个NorthScaleClient的对象成本很高,所以这里要使用静态变量private static NorthScaleClient client。

2) 在NorthScale Memcached Server停运时,NorthScaleClient会抛出"none of the pool urls are working."的异常,而不是写入日志,这样会影响网站的正常访问。建议在静态构造函数中创建NorthScaleClient对象,在创建对象失败时捕获异常并写入日志。

在高性能.NET Web应用开发中,缓存是很重要的环节,之前.NET平台缺少好的缓存解决方案,而NorthScale Memcached Server+EnyimMemcached客户端让我们眼前一亮。

由于刚接触NorthScale Memcached Server,理解还不深,这篇随笔写得也很简单,只是希望能抛个砖,希望园子里有更多朋友分享与探讨在缓存方面的心得。



举报

相关推荐

0 条评论