Richie

Sometimes at night when I look up at the stars, and see the whole sky just laid out there, don't you think I ain't remembering it all. I still got dreams like anybody else, and ever so often, I am thinking about how things might of been. And then, all of a sudden, I'm forty, fifty, sixty years old, you know?

Using MemCached with NHibernate

There's nothing says how to use MemCached in NHibernate, here is the steps to approach this. It's very easy in fact.

1. Install and start MemCached. http://jehiah.cz/projects/memcached-win32/.

2. Copy the ICSharpCode.SharpZipLib.dll, Memcached.ClientLibrary.dll and NHibernate.Caches.MemCache.dll from NHB's bin dir to your app's dir.

3. Make sure the following configuration section exists in your app.config or web.config:
<configSections>
    
<section name="memcache"
         type
="NHibernate.Caches.MemCache.MemCacheSectionHandler,NHibernate.Caches.MemCache" />
</configSections>

<memcache>
    
<memcached host="127.0.0.1" port="11211" weight="2" />
</memcache>
The weight attribute correspond to SockIOPool.Weight property in Memcached.ClientLibrary, representing the buckets number assigned to the server. In other words it indicates the load ability among the MemCached servers.

4. Tell NHB which cache provider class you are using in hibernate.config:
<add key="hibernate.cache.provider_class" value="NHibernate.Caches.MemCache.MemCacheProvider,NHibernate.Caches.MemCache" />

In the end don't forget to give out your cache strategies in your .hbm files or queries.

The following is the configuration properties that can be used in the <session-factory> node in hibernate.config (documentations from .NET memcached client library):
failover(bool): If this flag is set to true and a socket fails to connect,  the pool will attempt to return a socket from another server if one exists.  If set to false, then getting a socket will return null if it fails to connect to the requested server.
initial_connections(Int32): the initial number of connections per server setting in the available pool.
maintenance_sleep(Int64): the sleep time(in milliseconds) between runs of the pool maintenance thread. If set to 0, then the maintenance thread will not be started.
max_busy(Int64): the maximum busy time(in milliseconds) for threads in the busy pool.
max_connections(Int32): the maximum number of spare connections allowed in the available pool.
max_idle(Int64): the maximum idle time for threads in the avaiable pool.
min_connections(Int32): the minimum number of spare connections to maintain in the available pool.
nagle(bool): the Nagle algorithm flag for the pool. If false, will turn off Nagle's algorithm on all sockets created.
socket_timeout(Int32): the socket timeout(in milliseconds) for reads.
socket_connect_timeout(Int32): the socket timeout(in milliseconds) for connects.
riccc
关注 - 4
粉丝 - 21
0
0
(请您对文章做出评价)
« 上一篇:C#调用命令行
» 下一篇:IIS HTML, CSS, Script, 图片等静态文件不更新问题

posted on 2007-10-13 17:27 riccc 阅读(3041) 评论(0) 编辑 收藏 所属分类: NHibernate

导航

News

最新闪存

  • google.com终于好了,只有google.cn才重定向到hk 03-26 09:11
  • 收到ubuntu光盘,一个月时间不到 03-25 19:29
  • 晕,发现没法访问google.com了,总是会跑到google.com.hk上面去。以前一直用google.com的,.cn基本不用 03-24 16:18
  • 终于用上chrome了,原来是symantec的原因,用--no-sandbox启动就ok 03-19 23:17
  • 更多闪存...

搜索

 
 

常用链接

我的标签

随笔档案

Ruby & Rails

其它

数据库

最新评论

阅读排行榜

评论排行榜