- 浏览: 84039 次
- 性别:
- 来自: 重庆
文章分类
最新评论
-
H_kx:
put()方法有个bug, 无法覆盖已有的key-value修 ...
JS之HashMap -
吉祥小兔娃:
好人啊
在Windows中搭建iPhone开发环境 -
pythonlord:
ForgiDaved 写道 还在下安装包,明天晚上回来试验 ...
在Windows中搭建iPhone开发环境 -
ForgiDaved:
还在下安装包,明天晚上回来试验下
在Windows中搭建iPhone开发环境 -
miracle2441:
已经安装成功了
在Windows中搭建iPhone开发环境
http://hi.baidu.com/yinaddress/blog/item/f333f0d9af38f93e33fa1c28.html(转自)
EhCache使用详细介绍(转)2010-01-07 10:39
Ehcache中不仅可以用配置文件来配置缓存,而在代码中也可以实现同样的功能。
CacheManager singletonManager = CacheManager.create();
Cache memoryOnlyCache = new Cache(“testCache”, 50000, false, false, 8, 2);
Cache test = singletonManager.getCache(“testCache”);
删除只需要调用singletonManager.removeCache(“testCache”);
Shotdown CacheManager
在使用完Ehcache后,必须要shutdown缓存。Ehcache中有自己的关闭机制,不过最好在你的代码中显示调用CacheManager.getInstance().shutdown();
1.EhCache是什么
EhCache是Hibernate的二级缓存技术之一,可以把查询出来的数据存储在内存或者磁盘,节省下次同样查询语句再次查询数据库,大幅减轻数据库压力;
2.EhCache的使用注意点
当用Hibernate的方式修改表数据(save,update,delete等等),这时EhCache会自动把缓存中关于此表的所有缓存全部删除掉(这样能达到同步)。但对于数据经常修改的表来说,可能就失去缓存的意义了(不能减轻数据库压力);
3.EhCache使用的场合
3.1比较少更新表数据
EhCache一般要使用在比较少执行write操作的表(包括update,insert,delete等)[Hibernate的二级缓存也都是这样];
3.2对并发要求不是很严格的情况
两台机子中的缓存是不能实时同步的;
4.在项目做的实现
4.1在工程的src目录下添加ehcache.xml文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<diskStore path="java.io.tmpdir" />
<defaultCache maxElementsInMemory="5"<!--缓存可以存储的总记录量-->
eternal="false"<!--缓存是否永远不销毁-->
overflowToDisk="true"<!--当缓存中的数据达到最大值时,是否把缓存数据写入磁盘-->
timeToIdleSeconds="15"<!--当缓存闲置时间超过该值,则缓存自动销毁-->
timeToLiveSeconds="120"<!--缓存创建之后,到达该缓存自动销毁-->
/>
</ehcache>
4.2在Hibernate.cfg.xml中的mapping标签上面加以下内容:
<property name="show_sql">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.use_query_cache">true</property>
4.3在要缓存的bean的hbm.xml文件中的class标签下加入以下内容:
<cache usage="read-only" /><!--也可读写-->
4.4创建DAO,内容如下:
Session s = HibernateSessionFactory.getSession();
Criteria c = s.createCriteria(Xyz.class);
c.setCacheable(true);//这句必须要有
System.out.println("第一次读取");
List l = c.list();
System.out.println(l.size());
HibernateSessionFactory.closeSession();
s = HibernateSessionFactory.getSession();
c = s.createCriteria(Xyz.class);
c.setCacheable(true);//这句必须要有
System.out.println("第二次读取");
l = c.list();
System.out.println(l.size());
HibernateSessionFactory.closeSession();
4.5这时你会看到打印出来的信息为(表示第二次并没有去读库):
第一次读取
Hibernate: *******
13
第二次读取
13
配置Spring+hibernate使用ehcache作为second-level cache
大量数据流动是web应用性能问题常见的原因,而缓存被广泛的用于优化数据库应用。cache被设计为通过保存从数据库里load的数据来减少应用和数据库之间的数据流动。数据库访问只有当检索的数据不在cache里可用时才必要。hibernate可以用两种不同的对象缓存:first-level cache 和 second-level cache。first-level cache和Session对象关联,而second-level cache是和Session Factory对象关联。
缺省地,hibernate已经使用基于每个事务的first-level cache。 Hibernate用first-level cache主要是减少在一个事务内的sql查询数量。例如,如果一个对象在同一个事务内被修改多次,hibernate将只生成一个包括所有修改的 UPDATE SQL语句。为了减少数据流动,second-level cache在Session Factory级的不同事务之间保持load的对象,这些对象对整个应用可用,不只是对当前用户正在运行的查询。这样,每次查询将返回已经load在缓存里的对象,避免一个或更多潜在的数据库事务。
下载ehcache,hibernate3.2必须要ehcache1.2以上才能支持。可以修改log4j配置文件log4j.logger.net.sf.hibernate.cache=debug查看日志
1.在类路径上ehcache.xml:
<ehcache>
<!-- Sets the path to the directory where cache .data files are created.
If the path is a Java System Property it is replaced by
its value in the running VM.
The following properties are translated:
user.home - User's home directory
user.dir - User's current working directory
java.io.tmpdir - Default temp file path -->
<diskStore path="java.io.tmpdir"/>
<!--Default Cache configuration. These will applied to caches programmatically created through
the CacheManager.
The following attributes are required:
maxElementsInMemory - Sets the maximum number of objects that will be created in memory
eternal - Sets whether elements are eternal. If eternal, timeouts are ignored and the
element is never expired.
overflowToDisk - Sets whether elements can overflow to disk when the in-memory cache
has reached the maxInMemory limit.
The following attributes are optional:
timeToIdleSeconds - Sets the time to idle for an element before it expires.
i.e. The maximum amount of time between accesses before an element expires
Is only used if the element is not eternal.
Optional attribute. A value of 0 means that an Element can idle for infinity.
The default value is 0.
timeToLiveSeconds - Sets the time to live for an element before it expires.
i.e. The maximum time between creation time and when an element expires.
Is only used if the element is not eternal.
Optional attribute. A value of 0 means that and Element can live for infinity.
The default value is 0.
diskPersistent - Whether the disk store persists between restarts of the Virtual Machine.
The default value is false.
diskExpiryThreadIntervalSeconds- The number of seconds between runs of the disk expiry thread. The default value
is 120 seconds.
-->
<defaultCache
maxElementsInMemory="10000"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"/>
<!-- See http://ehcache.sourceforge.net/documentation/#mozTocId258426 for how to configure caching for your objects -->
</ehcache>
2.applicationContext-hibernate.xml里Hibernate SessionFactory配置:
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation"><value>classpath:hibernate.cfg.xml</value></property>
<!-- The property below is commented out b/c it doesn't work when run via
Ant in Eclipse. It works fine for individual JUnit tests and in IDEA ??
<property name="mappingJarLocations">
<list><value>file:dist/appfuse-dao.jar</value></list>
</property>
-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">@HIBERNATE-DIALECT@</prop>
<!--<prop key="hibernate.show_sql">true</prop>-->
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.hibernate.use_outer_join">true</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<!--
<prop key="hibernate.use_sql_comments">false</prop>
-->
<!-- Create/update the database tables automatically when the JVM starts up
<prop key="hibernate.hbm2ddl.auto">update</prop> -->
<!-- Turn batching off for better error messages under PostgreSQL
<prop key="hibernate.jdbc.batch_size">0</prop> -->
</props>
</property>
<property name="entityInterceptor">
<ref local="auditLogInterceptor"/>
</property>
</bean>
说明:如果不设置“查询缓存”,那么hibernate只会缓存使用load()方法获得的单个持久化对象,如果想缓存使用findall()、 list()、Iterator()、createCriteria()、createQuery()等方法获得的数据结果集的话,就需要设置 hibernate.cache.use_query_cache true 才行
3.model类里采用Xdoclet生成*.hbm.xml里的cache xml标签,即<cache usage="read-only"/>
/**
* @hibernate.class table="WF_WORKITEM_HIS"
* @hibernate.cache usage="read-write"
*
*/
4.对于"query cache",需要在程序里编码:
getHibernateTemplate().setCacheQueries(true);
return getHibernateTemplate().find(hql);
使用spring和hibernate配置ehcache和query cache1、applicationContext.xml
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
这两句加到hibernateProperties中
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
<property name="cacheQueries">
<value>true</value>
</property>
</bean>
添加此bean到applicationcontext.xml中。在各个DAO的bean中,更改如下
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
改为
<property name="hibernateTemplate">
<ref bean="hibernateTemplate" />
</property>
2、ehcache.xml文件放在classes根目录即可
3、pojo与ehcache.xml的配置关系
以com.ce.ceblog.pojos.CeblogJournal为例子
在CeblogJournal.hbm.xml中配置:
<class name="CeblogJournal" table="CEBLOG_JOURNAL" lazy="false">
<cache usage="read-write" region="ehcache.xml中的name的属性值"/>
注意:这一句需要紧跟在class标签下面,其他位置无效。
Ehcache.xml文件主体如下
<defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="1" timeToLiveSeconds="1" overflowToDisk="true" />
<cache name="com.ce.ceblog.pojos.CeblogJournal" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="true" />
hbm文件查找cache方法名的策略:如果不指定hbm文件中的region="ehcache.xml中的name的属性值",则使用name名为 com.ce.ceblog.pojos.CeblogJournal的cache,如果不存在与类名匹配的cache名称,则用 defaultCache。
如果CeblogJournal包含set集合,则需要另行指定其cache
例如CeblogJournal包含ceblogReplySet集合,则需要
添加如下配置到ehcache.xml中
<cache name="com.ce.ceblog.pojos.CeblogJournal.ceblogReplySet"
maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300"
timeToLiveSeconds="600" overflowToDisk="true" />
另,针对查询缓存的配置如下:
<cache name="org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="5000"
eternal="true"
overflowToDisk="true"/>
<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="10000"
eternal="false"
timeToLiveSeconds="120"
overflowToDisk="true"/>
4、选择缓存策略依据:
<cache usage="transactional|read-write|nonstrict-read-write|read-only" />
ehcache不支持transactional,其他三种可以支持。
read- only:无需修改, 那么就可以对其进行只读 缓存,注意,在此策略下,如果直接修改数据库,即使能够看到前台显示效果,但是将对象修改至cache中会报error,cache不会发生作用。另:删 除记录会报错,因为不能在read-only模式的对象从cache中删除。
read-write:需要更新数据,那么使用读/写缓存 比较合适,前提:数据库不可以为serializable transaction isolation level(序列化事务隔离级别)
nonstrict-read-write:只偶尔需要更新数据(也就是说,两个事务同时更新同一记录的情况很不常见),也不需要十分严格的事务隔离,那么比较适合使用非严格读/写缓存策略。
5、调试时候使用log4j的log4j.logger.org.hibernate.cache=debug,更方便看到ehcache的操作过程,主要用于调试过程,实际应用发布时候,请注释掉,以免影响性能。
6、 使用ehcache,打印sql语句是正常的,因为query cache设置为true将会创建两个缓存区域:一个用于保存查询结果集 (org.hibernate.cache.StandardQueryCache);另一个则用于保存最近查询的一系列表的时间戳(org.hibernate.cache.UpdateTimestampsCache)。请注意:在查询缓存中,它并不缓存结果集中所包含的实体的确切状态;它只缓存这些实体的标识符属性的值、以及各值类型的结果。需要将打印sql语句与最近的cache内容相比较,将不同之处修改到cache中,所以查询缓存通常会和二级缓存一起使用。
EhCache使用详细介绍(转)2010-01-07 10:39
Ehcache中不仅可以用配置文件来配置缓存,而在代码中也可以实现同样的功能。
CacheManager singletonManager = CacheManager.create();
Cache memoryOnlyCache = new Cache(“testCache”, 50000, false, false, 8, 2);
Cache test = singletonManager.getCache(“testCache”);
删除只需要调用singletonManager.removeCache(“testCache”);
Shotdown CacheManager
在使用完Ehcache后,必须要shutdown缓存。Ehcache中有自己的关闭机制,不过最好在你的代码中显示调用CacheManager.getInstance().shutdown();
1.EhCache是什么
EhCache是Hibernate的二级缓存技术之一,可以把查询出来的数据存储在内存或者磁盘,节省下次同样查询语句再次查询数据库,大幅减轻数据库压力;
2.EhCache的使用注意点
当用Hibernate的方式修改表数据(save,update,delete等等),这时EhCache会自动把缓存中关于此表的所有缓存全部删除掉(这样能达到同步)。但对于数据经常修改的表来说,可能就失去缓存的意义了(不能减轻数据库压力);
3.EhCache使用的场合
3.1比较少更新表数据
EhCache一般要使用在比较少执行write操作的表(包括update,insert,delete等)[Hibernate的二级缓存也都是这样];
3.2对并发要求不是很严格的情况
两台机子中的缓存是不能实时同步的;
4.在项目做的实现
4.1在工程的src目录下添加ehcache.xml文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<diskStore path="java.io.tmpdir" />
<defaultCache maxElementsInMemory="5"<!--缓存可以存储的总记录量-->
eternal="false"<!--缓存是否永远不销毁-->
overflowToDisk="true"<!--当缓存中的数据达到最大值时,是否把缓存数据写入磁盘-->
timeToIdleSeconds="15"<!--当缓存闲置时间超过该值,则缓存自动销毁-->
timeToLiveSeconds="120"<!--缓存创建之后,到达该缓存自动销毁-->
/>
</ehcache>
4.2在Hibernate.cfg.xml中的mapping标签上面加以下内容:
<property name="show_sql">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.use_query_cache">true</property>
4.3在要缓存的bean的hbm.xml文件中的class标签下加入以下内容:
<cache usage="read-only" /><!--也可读写-->
4.4创建DAO,内容如下:
Session s = HibernateSessionFactory.getSession();
Criteria c = s.createCriteria(Xyz.class);
c.setCacheable(true);//这句必须要有
System.out.println("第一次读取");
List l = c.list();
System.out.println(l.size());
HibernateSessionFactory.closeSession();
s = HibernateSessionFactory.getSession();
c = s.createCriteria(Xyz.class);
c.setCacheable(true);//这句必须要有
System.out.println("第二次读取");
l = c.list();
System.out.println(l.size());
HibernateSessionFactory.closeSession();
4.5这时你会看到打印出来的信息为(表示第二次并没有去读库):
第一次读取
Hibernate: *******
13
第二次读取
13
配置Spring+hibernate使用ehcache作为second-level cache
大量数据流动是web应用性能问题常见的原因,而缓存被广泛的用于优化数据库应用。cache被设计为通过保存从数据库里load的数据来减少应用和数据库之间的数据流动。数据库访问只有当检索的数据不在cache里可用时才必要。hibernate可以用两种不同的对象缓存:first-level cache 和 second-level cache。first-level cache和Session对象关联,而second-level cache是和Session Factory对象关联。
缺省地,hibernate已经使用基于每个事务的first-level cache。 Hibernate用first-level cache主要是减少在一个事务内的sql查询数量。例如,如果一个对象在同一个事务内被修改多次,hibernate将只生成一个包括所有修改的 UPDATE SQL语句。为了减少数据流动,second-level cache在Session Factory级的不同事务之间保持load的对象,这些对象对整个应用可用,不只是对当前用户正在运行的查询。这样,每次查询将返回已经load在缓存里的对象,避免一个或更多潜在的数据库事务。
下载ehcache,hibernate3.2必须要ehcache1.2以上才能支持。可以修改log4j配置文件log4j.logger.net.sf.hibernate.cache=debug查看日志
1.在类路径上ehcache.xml:
<ehcache>
<!-- Sets the path to the directory where cache .data files are created.
If the path is a Java System Property it is replaced by
its value in the running VM.
The following properties are translated:
user.home - User's home directory
user.dir - User's current working directory
java.io.tmpdir - Default temp file path -->
<diskStore path="java.io.tmpdir"/>
<!--Default Cache configuration. These will applied to caches programmatically created through
the CacheManager.
The following attributes are required:
maxElementsInMemory - Sets the maximum number of objects that will be created in memory
eternal - Sets whether elements are eternal. If eternal, timeouts are ignored and the
element is never expired.
overflowToDisk - Sets whether elements can overflow to disk when the in-memory cache
has reached the maxInMemory limit.
The following attributes are optional:
timeToIdleSeconds - Sets the time to idle for an element before it expires.
i.e. The maximum amount of time between accesses before an element expires
Is only used if the element is not eternal.
Optional attribute. A value of 0 means that an Element can idle for infinity.
The default value is 0.
timeToLiveSeconds - Sets the time to live for an element before it expires.
i.e. The maximum time between creation time and when an element expires.
Is only used if the element is not eternal.
Optional attribute. A value of 0 means that and Element can live for infinity.
The default value is 0.
diskPersistent - Whether the disk store persists between restarts of the Virtual Machine.
The default value is false.
diskExpiryThreadIntervalSeconds- The number of seconds between runs of the disk expiry thread. The default value
is 120 seconds.
-->
<defaultCache
maxElementsInMemory="10000"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"/>
<!-- See http://ehcache.sourceforge.net/documentation/#mozTocId258426 for how to configure caching for your objects -->
</ehcache>
2.applicationContext-hibernate.xml里Hibernate SessionFactory配置:
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation"><value>classpath:hibernate.cfg.xml</value></property>
<!-- The property below is commented out b/c it doesn't work when run via
Ant in Eclipse. It works fine for individual JUnit tests and in IDEA ??
<property name="mappingJarLocations">
<list><value>file:dist/appfuse-dao.jar</value></list>
</property>
-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">@HIBERNATE-DIALECT@</prop>
<!--<prop key="hibernate.show_sql">true</prop>-->
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.hibernate.use_outer_join">true</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<!--
<prop key="hibernate.use_sql_comments">false</prop>
-->
<!-- Create/update the database tables automatically when the JVM starts up
<prop key="hibernate.hbm2ddl.auto">update</prop> -->
<!-- Turn batching off for better error messages under PostgreSQL
<prop key="hibernate.jdbc.batch_size">0</prop> -->
</props>
</property>
<property name="entityInterceptor">
<ref local="auditLogInterceptor"/>
</property>
</bean>
说明:如果不设置“查询缓存”,那么hibernate只会缓存使用load()方法获得的单个持久化对象,如果想缓存使用findall()、 list()、Iterator()、createCriteria()、createQuery()等方法获得的数据结果集的话,就需要设置 hibernate.cache.use_query_cache true 才行
3.model类里采用Xdoclet生成*.hbm.xml里的cache xml标签,即<cache usage="read-only"/>
/**
* @hibernate.class table="WF_WORKITEM_HIS"
* @hibernate.cache usage="read-write"
*
*/
4.对于"query cache",需要在程序里编码:
getHibernateTemplate().setCacheQueries(true);
return getHibernateTemplate().find(hql);
使用spring和hibernate配置ehcache和query cache1、applicationContext.xml
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
这两句加到hibernateProperties中
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
<property name="cacheQueries">
<value>true</value>
</property>
</bean>
添加此bean到applicationcontext.xml中。在各个DAO的bean中,更改如下
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
改为
<property name="hibernateTemplate">
<ref bean="hibernateTemplate" />
</property>
2、ehcache.xml文件放在classes根目录即可
3、pojo与ehcache.xml的配置关系
以com.ce.ceblog.pojos.CeblogJournal为例子
在CeblogJournal.hbm.xml中配置:
<class name="CeblogJournal" table="CEBLOG_JOURNAL" lazy="false">
<cache usage="read-write" region="ehcache.xml中的name的属性值"/>
注意:这一句需要紧跟在class标签下面,其他位置无效。
Ehcache.xml文件主体如下
<defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="1" timeToLiveSeconds="1" overflowToDisk="true" />
<cache name="com.ce.ceblog.pojos.CeblogJournal" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="true" />
hbm文件查找cache方法名的策略:如果不指定hbm文件中的region="ehcache.xml中的name的属性值",则使用name名为 com.ce.ceblog.pojos.CeblogJournal的cache,如果不存在与类名匹配的cache名称,则用 defaultCache。
如果CeblogJournal包含set集合,则需要另行指定其cache
例如CeblogJournal包含ceblogReplySet集合,则需要
添加如下配置到ehcache.xml中
<cache name="com.ce.ceblog.pojos.CeblogJournal.ceblogReplySet"
maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300"
timeToLiveSeconds="600" overflowToDisk="true" />
另,针对查询缓存的配置如下:
<cache name="org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="5000"
eternal="true"
overflowToDisk="true"/>
<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="10000"
eternal="false"
timeToLiveSeconds="120"
overflowToDisk="true"/>
4、选择缓存策略依据:
<cache usage="transactional|read-write|nonstrict-read-write|read-only" />
ehcache不支持transactional,其他三种可以支持。
read- only:无需修改, 那么就可以对其进行只读 缓存,注意,在此策略下,如果直接修改数据库,即使能够看到前台显示效果,但是将对象修改至cache中会报error,cache不会发生作用。另:删 除记录会报错,因为不能在read-only模式的对象从cache中删除。
read-write:需要更新数据,那么使用读/写缓存 比较合适,前提:数据库不可以为serializable transaction isolation level(序列化事务隔离级别)
nonstrict-read-write:只偶尔需要更新数据(也就是说,两个事务同时更新同一记录的情况很不常见),也不需要十分严格的事务隔离,那么比较适合使用非严格读/写缓存策略。
5、调试时候使用log4j的log4j.logger.org.hibernate.cache=debug,更方便看到ehcache的操作过程,主要用于调试过程,实际应用发布时候,请注释掉,以免影响性能。
6、 使用ehcache,打印sql语句是正常的,因为query cache设置为true将会创建两个缓存区域:一个用于保存查询结果集 (org.hibernate.cache.StandardQueryCache);另一个则用于保存最近查询的一系列表的时间戳(org.hibernate.cache.UpdateTimestampsCache)。请注意:在查询缓存中,它并不缓存结果集中所包含的实体的确切状态;它只缓存这些实体的标识符属性的值、以及各值类型的结果。需要将打印sql语句与最近的cache内容相比较,将不同之处修改到cache中,所以查询缓存通常会和二级缓存一起使用。
发表评论
-
EHCache 配置详解
2011-02-12 16:07 1764http://taink.iteye.com/blog/783 ... -
学习maven的使用,看到一篇很实用的入门教程
2010-10-19 13:49 1243学习maven的使用,看到一篇很实用的入门教程 - ph952 ... -
Java面试
2010-08-26 16:43 935http://blog.csdn.net/neu_200680 ... -
Apache-Mina2 ^ JBoss-netty3
2010-08-24 13:10 2359@1 一、Mina2是一个很不错的框架 感谢前辈给我们留下的宝 ... -
WebSite
2010-08-04 13:07 1141http://ajava.org/course/java/17 ... -
jvm虚拟机的默认Heap大小是64M
2010-06-21 11:22 1987java.lang.OutOfMemoryError: Jav ... -
lucene
2010-06-18 14:29 720http://forfuture1978.iteye.com/ ... -
Sphinx
2010-06-18 10:54 1112http://www.360doc.com/content/1 ... -
JavaEE FreeMarker
2010-06-10 13:21 1355关于freemarker (1)解决输出中文乱码问题: ... -
Java,Spring,Hibernate,ibatis
2010-04-16 13:23 1517在我们的系统设计过程 ... -
在Apache环境下成功的运行ASP.NET
2010-04-04 16:41 1122一是:在安装Apache HTTP Server的时候,如果我 ... -
JAVA C#
2010-04-02 14:51 791http://msdn.microsoft.com/zh-cn ... -
利用JAX-WS开发Web服务
2010-03-24 10:20 1316(转帖:)http://blog.chinaunix. ...
相关推荐
java.sun.com/xml/ns/javaee":include-prelude, "http://java.sun.com/xml/ns/javaee":include-coda, "http://java.sun.com/ xml/ns/javaee":deferred-syntax-allowed-as-literal, ...
tml-java-cache-ehcache.zip,用于tr8n sdkstml ehcache适配器的ehcache适配器
Java缓存框架 EhCache EhCache 是一个纯Java的进程内缓存框架,具有快速、精干等特点,是Hibernate中默认的CacheProvider。 从之前发布其他chm文件下载用户的反映看,有不少朋友反映下载后打开无法显示,这一般不是...
shiro-crypto-hash-1.7.1.jar,shiro-ehcache-1.7.1.jar,shiro-event-1.7.1.jar,shiro-guice-1.7.1.jar,shiro-hazelcast-1.7.1.jar,shiro-lang-1.7.1.jar,shiro-quartz-1.7.1.jar,shiro-spring-1.7.1.jar,shiro-web-...
Aspect Cache是一个针对Spring Boot,基于AOP注解方式的轻量级缓存,目前支持EHCache,Redis缓存方式。数据类型支持POJO、Map和List数据类型,同时支持自定义缓存key解析,也支持自定义的缓存处理方式,或者扩展支持...
Spring-Boot-Example Spring Boot 功能特性和组件系列的整合, 详解与使用。下面所有Demo都是基于 Spring Boot 2.0.x, 2.1.x, 2.2.x 版本。...4. spring-boot-cache-ehcache2 添加 ehcache2 依赖和 ehcache.
参考j2cache实现的j2cache v1.0 两级缓存结构 L1: 进程内缓存(ehcache) ,也可1级使用Redis,大多数项目的用法 L2: 集中式缓存,支持多种集中式缓存服务器,如 Redis 由于大量的缓存读取会导致 L2 的网络带宽成为...
Ehcache is a widely used java distributed cache for general purpose caching, Java EE and light-weight containers. It features memory and disk stores, replicate by copy and invalidate, listeners, cache...
Ehcache 是现在最流行的纯Java开源缓存框架,配置简单、结构清晰。该资源有ehcache-2.10.2.jar、slf4j-api-1.6.1.jar、slf4j-log4j12-1.6.2.jar及与mybatis整合的适配包mybatis-ehcache-1.0.3.jar
智能缓存介绍基于Ehcache2和Redis的Java分布式二级缓存,除了基本操作外,还可以实现所有级别的多计算机集群的缓存监视和获取。 将独立缓存与特定结构中的Redis缓存系统同步,以实现全局缓存的统一管理。 动态地使用...
connector.jar cos.jar dom4j-1.6.1.jar dwr.jar ehcache-1.1.jar ehcache-1.2.3.jar FCKeditor-2.3.jar freemarker.jar hibernate3.jar itext-1.3.jar jaas.jar jacc-1_0-fr.jar jakarta-oro-2.0.8.jar ...
EHCache 的特点,系统要求及安装 是一个纯Java ,过程中(也可以理解成插入式)缓存实现
任何缓存提供程序都可以用虚拟命名空间(mem-cached、ehcache 等)包装。 命名空间缓存可以与 Spring 一起使用或作为独立的解决方案使用。 建造 项目使用 maven 管理,所以只需点击: $mvn clean install 示例...
JAVA编程之spring cache本机缓存应用 spring cache简单实用,简介: 1、SpringCache是Spring提供的一个缓存框架,在Spring3.1版本开始支持将缓存添加到现有的spring应用程序中,在4.1开始,缓存已支持JSR-107注释和...
ehcache-1.5.0.jar ehcache缓存 hibernate3.jar hibernate-3.3.1.GA jar jaxen-1.1.1.jar 支持dom4j的xpath javassist-3.4.GA.jar 是一个开源的分析、编辑和创建Java字节码的类库,用于 Java 的加载时反射系统 jta-...
J2Cache —— 基于内存和 Redis 的两级 Java 缓存框架。J2Cache 是 OSChina 目前正在使用的两级缓存框架(要求至少 Java 8)。第一级缓存使用内存(同时支持 Ehcache 2.x、Ehcache 3.x 和 Caffeine),第二级缓存使用 ...
ehcache-1.2.jar Hibernate可以使用不同cache缓存工具作为二级缓存。EHCache是缺省的cache缓存工具。如果没有其它的可选缓存工具,则为必需的。 hibernate3.jar hibernate3的核心类库。 itext.jar 是用于生成...
axis webservic ehcache 的入门示例
ehcache是一个用Java实现的使用简单,高速,实现线程安全的缓存管理类库,ehcache提供了用内存,磁盘文件存储,以及分布式存储方式等多种灵活的cache管理方案,是hibernate中默认的CacheProvider。
ehcache-1.1.jar (1.1) - EHCache cache - runtime, optional (required if no other cache provider is set) versioncheck.jar (1.0) - version checker - buildtime swarmcache-1.0rc2.jar (1.0rc2) - runtime, ...