spring+hibernate
在hibernate配置文件中
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="sessionFactory">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">pass</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/cache</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLMyISAMDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.bytecode.use_reflection_optimizer">true</property>
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
<mapping resource="bean/Class.hbm.xml" />
<mapping resource="bean/Student.hbm.xml" />
<mapping resource="bean/Teacher.hbm.xml" />
</session-factory>
</hibernate-configuration>
然后写一个ehcache.xml在工程的classpath里,我的路径在src下面。
<?xml version="1.0" encoding="UTF-8"?> <ehcache> <diskStore path="d:\\ehcache" /> <defaultCache maxElementsInMemory="10000" eternal="false" overflowToDisk="true" timeToIdleSeconds="120" timeToLiveSeconds="600" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" /> <cache name="bean.Class" maxElementsInMemory="50" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="1800" overflowToDisk="true" /> </ehcache>
要是启动出现
2008-12-15 21:41:17 org.hibernate.cfg.SettingsFactory buildSettings
信息: Second-level cache: enabled
2008-12-15 21:41:17 org.hibernate.cfg.SettingsFactory buildSettings
信息: Query cache: enabled
2008-12-15 21:41:17 org.hibernate.cfg.SettingsFactory createCacheProvider
信息: Cache provider: org.hibernate.cache.EhCacheProvider
字样就表示配置成功了
针对Class这个类的session打开时,缓存就准备起作用了。要是查完东西关掉了,比如查了个select *,然后交给vo,关掉这个session,下次再打开这个session会怎么样?估计缓存也不见了。。。等会试一下看看什么情况。
囧……tomcat启动了,缺访问不了,我的妈呀,怎么试啊。