- 浏览: 330560 次
- 性别:
- 来自: 北京
最新评论
-
hoey168:
请问楼主,ICE 客户端连接多个服务端,tcp -h 172. ...
ZeroC ICE之旅------负载均衡及容错 -
iOracleSun:
makeC++SharedLib 增加 -G参数即可链接成功 ...
AIX apache module问题 -
fanyonglu:
不错,讲的很细,学习中
ZeroC ICE之旅------java -
click_guobin:
...
我在深圳,每月收入850元,怎么也花不完,晒一晒我是怎么开销和投资的(zz) -
hanyu332:
引用修改%apache%/conf/httpd.conf修改为 ...
awstats日志分析小结(1)
hibernate的缓存机制是其成为主流持久层霸主地位的重要组成部分。二级缓存是SessionFactory级别的全局缓存,可以通过配置文件的hibernate.cache.provider_class 进行指定。
目前Hiberante 的二级缓存实现方式:
大致分为上述8种缓存方案的实现,主要分为内存和文件两种方式进行存储。
hibernate的二级缓存默认是不开启的,就是采用NoCacheProvider
就提出较大的设想,采用Memcached作为hibernate的二级缓存存储方式。采用Memcached作为Hibernate的二级缓存具有良好的分布式特性。
多台基于Hiberante进行不部署部署,可以共享二级缓存,是不是很爽,赫赫!
在这里我们就采用Memcached作为hibernate的二级缓存。主要实现Hibernate的两个接口: org.hibernate.cache.Cache,org.hibernate.cache.CacheProvider,实现我们自己的方法。在这里,我们采用
如下代码只给出了关键思路和主要方法,一些异常,日志,属性文件操作等非关键代码没有加,算是一个Demo code吧。
下面定义:MemcachedCache ,
接着我们需要实现MemcachedCacheProvider
上述思路和代码希望能够起到抛砖引玉作用。
目前Hiberante 的二级缓存实现方式:
1.EhCache 2,Hashtable 3.JndiBoundTreeCache 4.NoCache 5.OptimisticTreeCache 6.OSCache 7.TreeCache 8.SwarmCache
大致分为上述8种缓存方案的实现,主要分为内存和文件两种方式进行存储。
hibernate的二级缓存默认是不开启的,就是采用NoCacheProvider
public static final String DEF_CACHE_PROVIDER = NoCacheProvider.class.getName();
就提出较大的设想,采用Memcached作为hibernate的二级缓存存储方式。采用Memcached作为Hibernate的二级缓存具有良好的分布式特性。
多台基于Hiberante进行不部署部署,可以共享二级缓存,是不是很爽,赫赫!
在这里我们就采用Memcached作为hibernate的二级缓存。主要实现Hibernate的两个接口: org.hibernate.cache.Cache,org.hibernate.cache.CacheProvider,实现我们自己的方法。在这里,我们采用
如下代码只给出了关键思路和主要方法,一些异常,日志,属性文件操作等非关键代码没有加,算是一个Demo code吧。
下面定义:MemcachedCache ,
package xxxx.memcached; import java.util.Map; import java.util.Properties; import org.hibernate.cache.Cache; import org.hibernate.cache.CacheException; import com.danga.MemCached.MemCachedClient; import com.danga.MemCached.SockIOPool; /* * Copyright By C.F @http://masterkey.iteye.com * hibernate with Memcached Cache * Memcached 1.2.x ,java_memcached from http://www.whalin.com/memcached/ * demo code */ public class MemCachedCache implements Cache { private MemCachedClient cacheClient; private String _regionName; public MemCachedCache(String regionName, Properties properties) { _regionName = regionName; //serverlist = cache1.int.meetup.com:12345;cache0.int.meetup.com:12345 String servers =(String)(properties.get("serverlist")); String[] serverlist = servers.split(";"); // initialize the pool for memcache servers SockIOPool pool = SockIOPool.getInstance(); pool.setServers( serverlist ); pool.setInitConn(Integer.parseInt((String)properties.get("InitConn"))); pool.setMinConn(Integer.parseInt((String)properties.get("MinConn"))); pool.setMaxConn(Integer.parseInt((String)properties.get("MaxConn"))); pool.setMaintSleep(Integer.parseInt((String)properties.get("MaintSleep"))); pool.setNagle(Boolean.parseBoolean((String)properties.get("Nagle"))); pool.initialize(); } public void clear() throws CacheException { // TODO Auto-generated method stub } public void destroy() throws CacheException { // TODO Auto-generated method stub } public Object get(Object key) throws CacheException { // TODO Auto-generated method stub return cacheClient.get(toString(key)); } public long getElementCountInMemory() { // TODO Auto-generated method stub return 0; } public long getElementCountOnDisk() { // TODO Auto-generated method stub return 0; } public String getRegionName() { // TODO Auto-generated method stub return _regionName; } public long getSizeInMemory() { // TODO Auto-generated method stub return 0; } public int getTimeout() { // TODO Auto-generated method stub return 0; } public void lock(Object key) throws CacheException { // TODO Auto-generated method stub } public long nextTimestamp() { // TODO Auto-generated method stub return 0; } public void put(Object key, Object value) throws CacheException { // TODO Auto-generated method stub cacheClient.set(toString(key), value); } public Object read(Object key) throws CacheException { // TODO Auto-generated method stub return get(key); } public void remove(Object key) throws CacheException { // TODO Auto-generated method stub cacheClient.delete(toString(key)); } public Map toMap() { // TODO Auto-generated method stub return null; } public void unlock(Object key) throws CacheException { // TODO Auto-generated method stub } public void update(Object key, Object value) throws CacheException { // TODO Auto-generated method stub cacheClient.replace(toString(key), value); } public String toString(Object key) { return _regionName+(String)key; } }
接着我们需要实现MemcachedCacheProvider
package xxxx.memcached; import java.util.Properties; import org.hibernate.cache.Cache; import org.hibernate.cache.CacheException; import org.hibernate.cache.CacheProvider; import org.hibernate.cache.Timestamper; import com.danga.MemCached.SockIOPool; /* * Copyright By C.F @http://masterkey.iteye.com * hibernate with Memcached Cache * Memcached 1.2.x ,java_memcached from http://www.whalin.com/memcached/ * demo code */ public class MemCachedProvider implements CacheProvider{ private SockIOPool pool; private MemCachedCache memcachedCache = null; public Cache buildCache(String regionName, Properties properties) throws CacheException { // TODO Auto-generated method stub return new MemCachedCache(regionName,properties); } public boolean isMinimalPutsEnabledByDefault() { // TODO Auto-generated method stub return false; } public long nextTimestamp() { // TODO Auto-generated method stub return Timestamper.next(); } public void start(Properties properties) throws CacheException { // TODO Auto-generated method stub } public void stop() { // TODO Auto-generated method stub if(null != pool) pool.shutDown(); } }
上述思路和代码希望能够起到抛砖引玉作用。
评论
4 楼
fangzhouxing
2009-03-01
多台基于Hiberante进行不部署部署???
3 楼
masterkey
2008-05-04
其实我感觉自己去实现业务的缓存会更加有效,有的放矢。
2 楼
YRHYRH
2008-04-30
现在分布式缓存技术的确是有市场的需求了。开源的方案也很多。缓存命中的效率才是最大的问题。hibernate复杂查询结果的缓存命中的效率问题很多。
1 楼
squirel
2008-04-25
good idea!
发表评论
-
Redis 2.2.0 RC1 is out
2010-12-17 10:15 1181Redis 2.2.0 RC1 新特性:很多都是我所期待的; ... -
iBATIS 3 for Java Released (BETA 1)
2009-08-09 13:52 1351A month ago iBATIS turned 7 yea ... -
Memcached 1.4.0 Release
2009-07-10 17:10 1866New Features Binary Protocol ... -
nginx-0.7.60
2009-06-16 09:01 1440Changes with nginx 0.7.60 ... -
nginx-0.7.55
2009-05-06 18:47 1095Changes with nginx 0.7.55 ... -
Open Source SSL Acceleration
2009-04-17 11:15 1686SSL acceleration is a techniq ... -
March 2009 Web Server Survey
2009-04-02 12:49 986In the March 2009 survey, we re ... -
nginx 缓存功能
2009-03-26 16:02 4382随着 nginx-0.7.44的发布,nginx的c ... -
Memcached Beta 1.3.2 Released
2009-03-12 16:21 1177We've just released memcached ... -
nginx 0.7.40
2009-03-09 17:09 987Changes with nginx 0.7.40 ... -
February 2009 Web Server Survey
2009-03-02 09:19 1032In the February 2009 survey we ... -
Handle 1 Billion Events Per Day Using a Memory Gri
2009-02-17 10:41 1005Moshe Kaplan of RockeTier shows ... -
Scaling Digg and Other Web Applications
2009-02-16 11:36 1054Joe Stump, Lead Architect at D ... -
MySpace Architecture
2009-02-13 10:39 1188Information Sources Presenta ... -
Cloud Relationship Model
2009-01-20 09:53 1112Hiya All, welcome to my first g ... -
January 2009 Web Server Survey
2009-01-19 15:33 1056In the January 2009 survey we ... -
December 2008 Web Server Survey
2008-12-25 17:47 973In the December 2008 survey, ... -
Apache 2.2.11
2008-12-15 13:24 1380Changes with Apache 2.2.11 * ... -
nginx 0.7.26
2008-12-09 12:05 1030Changes with nginx 0.7.26 ... -
Python 3.0 final released
2008-12-04 10:47 1330We are pleased to announce the ...
相关推荐
memcached作为hibernate二级缓存必备的jar包.包含hibernate-memcached-1.2.2.jar memcached-2.1.jar spy-2.4.jar
hibernate-memcached, 在Hibernate中,使用Memcached作为第二级分布式缓存的库 休眠 memcachedHibernate中使用Memcached作为第二级分布式缓存的库。基于优秀的spymemcached客户端包含对 Whalin ( danga ) memcached...
用memcached实现 Hibernate4二级缓存的实例源码。
ehcache 二级缓存 配置使用的jar包 配置如下: <!-- 启用二级缓存 --> <property name="hibernate.cache.use_second_level_cache">true <!-- 查询的二级缓存配置 --> <property name="hibernate....
NULL 博文链接:https://dixian.iteye.com/blog/930677
解决目前memcached不支持hibernate4的缺陷,hibernate配置<property name="hibernate.cache.region.factory_class">com.googlecode.hibernate.memcached.MemcachedRegionFactory</property>
用于hibernate集成memcached作为二级缓存所需要的包,1.2.2版本
hibernate使用memcached作为二级缓存所需要的资源包,包括memcached的windows安装文件、hibernate3和hibernate4整合memcached的jar包 文件目录:commons-codec-1.10.jar、hibernate3-memcached-1.5.jar、hibernate4-...
2、L2二级缓存的支持,考虑到应用分布式部署的原因,数据只能通过Memcached和Redis进行缓存。3、Hibernate和Mybatis的集成,DB的事务管理由Hibernate提供支持,所以一般增删改的操作由Hibernate来完成,而查询则交由...
23、Mybatis 的一级、二级缓存 24、什么是 MyBatis 的接口绑定?有哪些实现方式? 25、使用 MyBatis 的 mapper 接口调用时有哪些要求? 26、Mapper 编写有哪几种方式? 27、简述 Mybatis 的插件运行原理,以及...
支持使用Redis和Memcached作为后端缓存。3. 支持缓存数据分区规则的定义 4. 使用redis作缓存时,支持list类型的高级数据结构,更适合论坛帖子列表这种类型的数据 5. 支持混合使用redis缓存和memcached缓存。可以将...
支持使用Redis和Memcached作为后端缓存。3. 支持缓存数据分区规则的定义 4. 使用redis作缓存时,支持list类型的高级数据结构,更适合论坛帖子列表这种类型的数据 5. 支持混合使用redis缓存和memcached缓存。可以将...
支持使用Redis和Memcached作为后端缓存。3. 支持缓存数据分区规则的定义 4. 使用redis作缓存时,支持list类型的高级数据结构,更适合论坛帖子列表这种类型的数据 5. 支持混合使用redis缓存和memcached缓存。可以将...
支持使用Redis和Memcached作为后端缓存。3. 支持缓存数据分区规则的定义 4. 使用redis作缓存时,支持list类型的高级数据结构,更适合论坛帖子列表这种类型的数据 5. 支持混合使用redis缓存和memcached缓存。可以将...
支持使用Redis和Memcached作为后端缓存。3. 支持缓存数据分区规则的定义 4. 使用redis作缓存时,支持list类型的高级数据结构,更适合论坛帖子列表这种类型的数据 5. 支持混合使用redis缓存和memcached缓存。可以将...
支持使用Redis和Memcached作为后端缓存。3. 支持缓存数据分区规则的定义 4. 使用redis作缓存时,支持list类型的高级数据结构,更适合论坛帖子列表这种类型的数据 5. 支持混合使用redis缓存和memcached缓存。可以将...
支持使用Redis和Memcached作为后端缓存。3. 支持缓存数据分区规则的定义 4. 使用redis作缓存时,支持list类型的高级数据结构,更适合论坛帖子列表这种类型的数据 5. 支持混合使用redis缓存和memcached缓存。可以将...
支持使用Redis和Memcached作为后端缓存。3. 支持缓存数据分区规则的定义 4. 使用redis作缓存时,支持list类型的高级数据结构,更适合论坛帖子列表这种类型的数据 5. 支持混合使用redis缓存和memcached缓存。可以将...
支持使用Redis和Memcached作为后端缓存。3. 支持缓存数据分区规则的定义 4. 使用redis作缓存时,支持list类型的高级数据结构,更适合论坛帖子列表这种类型的数据 5. 支持混合使用redis缓存和memcached缓存。可以将...
支持使用Redis和Memcached作为后端缓存。3. 支持缓存数据分区规则的定义 4. 使用redis作缓存时,支持list类型的高级数据结构,更适合论坛帖子列表这种类型的数据 5. 支持混合使用redis缓存和memcached缓存。可以将...