现在的位置: 首页 > 综合 > 正文

hibernate-memcached–在Hibernate中使用Memcached作为一个二级分布式缓存

2013年07月06日 ⁄ 综合 ⁄ 共 1337字 ⁄ 字号 评论关闭
 今天在网上看到一个用Memcached作为Hibernate二级分布式缓存,感觉挺有兴趣,就是尝试用了,感觉还不错,就推荐给大家看一下。

官方网址: http://code.google.com/p/hibernate-memcached/
目前最新版本为1.0RC1, 支持Hibernate3.3.

下面是具体的使用方法:
hibernate-memcached需要支持的类库如下:

配置方法如下:

配置Hibernate使用cache提供类

hibernate.cache.provider_class com.googlecode.hibernate.memcached.MemcachedCacheProvider

设置查询缓存开启

hibernate.cache.use_query_cache true

其它一些参数设置说明:

Property Default Description
hibernate.memcached.servers localhost:11211 memcached 服务地址,多个用空格分隔
格式host:port
hibernate.memcached.cacheTimeSeconds 300 缓存失效时间,单位秒
hibernate.memcached.keyStrategy HashCodeKeyStrategy 缓存Key生成存储HashCode算法
hibernate.memcached.readBufferSize DefaultConnectionFactory.DEFAULT_READ_BUFFER_SIZE 从服务器读取数据缓存区大小
hibernate.memcached.operationQueueLength DefaultConnectionFactory.DEFAULT_OP_QUEUE_LEN Maximum length of the operation queue returned by this connection factory
hibernate.memcached.operationTimeout DefaultConnectionFactory.DEFAULT_OPERATION_TIMEOUT 操作超时时间设置
hibernate.memcached.hashAlgorithm HashAlgorithm.KETAMA_HASH 新增缓存数据到服务器时使用的Hash散列算法。 当 hibernate-memcached 设置成 KETAMA_HASH算法时,注意:默认客户端API使用的是 HashAlgorithm.NATIVE_HASH
hibernate.memcached.clearSupported false 支持MemcachedCache.clear()方法清空缓存。
建议不要开启。

关于性能这块没有具体测试,如果有朋友尝试,也希望能通知本人一下。

Good Luck!
Yours Matthew!

抱歉!评论已关闭.