`
movingboy
  • 浏览: 55611 次
社区版块
存档分类
最新评论

hibernate-memcached补丁:支持Whalin的MemCached Java客户端

    博客分类:
  • Java
阅读更多

hibernate-memcached(http://code.google.com/p/hibernate-memcached/ )是允许hibernate使用MemCached作为二级缓存的项目,它用到了spymemcached(http://code.google.com/p/spymemcached/ )这个MemCached的Java客户端。花了一点时间做了个补丁,让它也支持Whalin的Java客户端(http://whalin.com/memcached/ )。

所有的代码(包括原hibernate-memcached的所有源码)、javadoc及重新制作的发布包请见附件,限于篇幅就不具体说明了。以下是我更新过的hibernate-memcached的配置说明,原配置说明请参见http://code.google.com/p/hibernate-memcached/wiki/Configuration

 

Adding hibernate-memcached to your application

If you are using Maven2 for your application build you can follow the instructions on the MavenRepository page. For those that aren't using Maven2 you'll need to collect a few simple jars for yourself. I am going to assume you already have hibenrnate3 setup before you came here.

You'll need...

If you are using spymemcached as the MemCached client, you also need

or if you prefer Whalin's memcached client for java , you need to download java_memcached-release_2.0.1.jar from the download page according to your Java VM version.

Configuring Hibernate

The first thing to do is to tell hibernate which cache provider you'd like to use, and to enable the second level cache.

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

Using just the property above you get basic entity caching by default. The hibernate-memcached library supports query caching, but you have to enable query caching separately.

hibernate.cache.use_query_cache true

!Now you can start setting up the hibernate-memcached specific properties. The hibernate-memcached properties are divided into two categories; cache-wide settings and cache-region settings.

Cache Wide Settings

The cache wide settings all have defaults can mostly be overwritten at a cache-region level. For both spymemcached and Whalin's client, you can set:

Property Default Description
hibernate.memcached.servers localhost:11211 Space delimited list of memcached instances in host:port format
hibernate.memcached.cacheTimeSeconds 300 The default number of seconds items should be cached. Can be overriden at the regon level.
hibernate.memcached.keyStrategy HashCodeKeyStrategy Sets the strategy class to to use for generating cache keys. Must provide a class name that implements KeyStrategy
hibernate.memcached.clearSupported false Enables support for the MemcachedCache.clear() method for all cache regions. The way clear is implemented for memcached is expensive and adds overhead to all get/set operations. It is not recommended for production use.

For spymemcached, you can set:

hibernate.memcached.readBufferSize DefaultConnectionFactory.DEFAULT_READ_BUFFER_SIZE The read buffer size for each server connection from this factory
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 Default operation timeout in milliseconds
hibernate.memcached.hashAlgorithm HashAlgorithm.KETAMA_HASH Which hash algorithm to use when adding items to the cache. Note: the MemcachedClient defaults to using HashAlgorithm.NATIVE_HASH, while the hibernate-memcached cache defaults to KETAMA_HASH for "consistent hashing"

For Whalin's client, you can set:

hibernate.memcached.weights Space delimited list of server weights. If not set, all servers get the same weight
hibernate.memcached.errorHandler com.googlecode.hibernate.memcached.
dangamemcached.SimpleErrorHandler
Error handler used by Whalin's client internally
hibernate.memcached.poolName default The name of SockIOPool
hibernate.memcached.initConn 1 Initial pool size
hibernate.memcached.minConn 1 Min pool size
hibernate.memcached.maxConn 10 Max pool size
hibernate.memcached.maxIdle 3000000 Max idle time for available sockets. Default 5 minutes
hibernate.memcached.socketTimeout 30000 Default timeout of socket reads. Default 30 seconds
hibernate.memcached.socketConnectTimeout 3000 Default timeout of socket connections. Default 3 seconds
hibernate.memcached.maintSleep 30000 Maintenance thread sleep time. Default 30 seconds
hibernate.memcached.compressEnable true If compression enabled
hibernate.memcached.defaultEncoding UTF-8 Default encoding

Cache Region Settings

Cache regon properties are set by giving your cached data a "region name" in hibernate. You can tune the MemcachedCache instance for your region using the following properties. These properties essentially override the cache-wide properties above.

Property Default Description
hibernate.memcached.[region-name].cacheTimeSeconds none, see hibernate.memcached.cacheTimeSeconds Set the cache time for this cache region, overriding the cache-wide setting.
hibernate.memcached.[region-name].keyStrategy none, see hibernate.memcached.keyStrategy Overrides the strategy class to to use for generating cache keys in this cache region. Must provide a class name that implements KeyStrategy
hibernate.memcached.[region-name].clearSupported none, see hibernate.memcached.clearSupported Enables clear() operations for this cache region only. Again, the clear operation incurs cost on every get/set operation.
分享到:
评论
2 楼 raymond2006k 2008-10-13  
不错的资料, 最近正需要呢,多谢啦。
有问题再请教你。
1 楼 movingboy 2008-10-09  
还是要说明一下:

附件里的代码中,包com.googlecode.hibernate.memcached.dangamemcached中的代码是我加的,其它的是原项目中的代码。我已经发邮件给Ray Krueger,把我的代码捐赠给了这个项目,因为Ray还收到了另一份捐赠的Whalin补丁,现在还不知道他到底会采用谁的代码。不管怎样,希望这个项目越来越好

上面的配置中忘了提到一点:使用Whalin的客户端时,还必须把hibernate.memcached.memcacheClientFactory设为com.googlecode.hibernate.memcached.whalin.DangaMemcacheClientFactory

相关推荐

    hibernate-memcached包

    **hibernate-memcached-1.2.2.jar** 文件是这个扩展的核心库,其中包含了所有必要的类和接口,使得Hibernate能够识别并使用Memcached作为二级缓存。这个版本的hibernate-memcached已经过测试和优化,确保与1.2.2版本...

    hibernate-memcached-1.5.jar

    这个包是最高版本了,google code是1.22,但是这个版本是基础班的1.5版本.是github上源代码经过我打包出来的jar

    hibernate-memcached-1.1.0-sources.zip

    《Hibernate与Memcached整合详解——基于hibernate-memcached-1.1.0源码分析》 在当今的Web开发领域,数据持久化是一个必不可少的环节,而Hibernate作为Java领域广泛使用的对象关系映射(ORM)框架,极大地简化了...

    hibernate-memcached-1.1.0.jar

    hibernate-memcached-1.1.0.jar

    hibernate-memcached, 在Hibernate中,使用Memcached作为第二级分布式缓存的库.zip

    hibernate-memcached, 在Hibernate中,使用Memcached作为第二级分布式缓存的库 休眠 memcachedHibernate中使用...基于优秀的spymemcached客户端包含对 Whalin ( danga ) memcached客户端的支持支持实体和查询缓存。帮

    java-memcached-2.6.6.jar

    java-memcached-2.6.6.jar

    hibernate-memcached-1.1.0-javadoc.zip

    《Hibernate与Memcached结合使用详解》 ...总之,Hibernate与Memcached的结合使用,为Java Web应用提供了一种高效的数据缓存解决方案。通过深入理解和实践,开发者可以充分利用这一特性,优化应用性能,提升用户体验。

    项目中使用 hibernate-memcached 做二级缓存

    本文将详述如何在项目中使用Hibernate与Memcached结合实现二级缓存,并探讨Memcached的基本原理和使用方法。 首先,我们需要理解什么是Hibernate的二级缓存。在Hibernate框架中,一级缓存是每个Session级别的,它...

    hibernate集成memcached所需jar

    memcached-2.5-sources.jar、hibernate-memcached-1.2.2-sources.jar、spy-2.4.jar这三个jar不太好找,剩下两个commons-codec和slf4j-log4j直接maven配置一下就行 <groupId>org.slf4j <artifactId>slf4j-log4j12 ...

    php-memcached-3.1.3.tar.gz

    安装php-memcached扩展 https://github.com/php-memcached-dev/php-memcached tar -zxvf ...-disable-memcached-sasl && make && make install

    hibernate-memcached

    hibernate-memcached,一个分布式缓存框架,很强大,这里提供hibernate集成jar

    python-memcached python-memcached

    Python-memcached是Python语言的一个库,用于与Memcached缓存系统进行交互。Memcached是一种高性能、分布式内存对象缓存系统,广泛应用于Web应用中,用于减轻数据库的负载,提高数据访问速度。Python-memcached库则...

    java_memcached-release_2.5.1.jar Memcache java jar 包

    在本例中,我们关注的是`java_memcached-release_2.5.1.jar`这个文件,这是一个包含了Java Memcached客户端库的JAR(Java Archive)包,版本号为2.5.1。 Java Memcached客户端库由Danga Interactive开发,该公司是...

    memcached-hibernate-1.3

    google上的这个包最多是1.2.2但是github上是1.3,源代码下载下来后,我打包为jar的

    spring-mybatis-memcached.zip_Memcached java_annotation_mybatis_m

    因为 mybatis-memcached 不支持 MyBatis2(iBatis),只能用在 MyBatis3 里。但是因为有的项目还跑在 MyBatis2 版本上,所以也做一个例子。 mm-mybatis3-memcached 使用了 mybatis-memcached 。因为 simple-spring-...

    python-memcached-latest.tar

    这个`python-memcached-latest.tar`压缩包包含了最新的Python绑定版本,即`python-memcached-1.53`。 **Python-Memcached库** Python-Memcached库为Python开发者提供了简单而高效的API,以便在应用中集成Memcached...

    memcached的三种java客户端jar

    3.xmemcached,XMemcached也使用得比较广泛,而且有较详细的中文API文档,具有如下特点:高性 能、支持完整的协议、支持客户端分布、允许设置节点权重、动态增删节点、支持JMX、与Spring框架和Hibernate-memcached的...

    memcached安装及java应用使用memcached

    3. **Java客户端库**:介绍常用的Java库,如spymemcached、xmemcached等,用于与memcached通信。 4. **配置Java应用**: - **添加依赖**:在Maven或Gradle项目中引入相应客户端库。 - **连接设置**:如何配置连接...

    hibernate整合memcached需要的jar包

    2. **memcached-2.3.1.jar**:这是Memcached的Java客户端库,负责与Memcached服务器通信。它包含了连接管理、序列化、异常处理等核心功能,使得Java应用能够方便地存取和检索数据。 3. **slf4j-api-1.7.12.jar**:...

    php-memcached-demo.tar.gz

    PHP-Memcached-Demo项目,通过一个压缩包形式(php-memcached-demo.tar.gz)提供了一个实战示例,帮助开发者了解并掌握如何在PHP环境中使用Memcached作为缓存服务,以实现数据的快速访问和存储。本文将深入探讨这一...

Global site tag (gtag.js) - Google Analytics