一级缓存:
当应用程序调用Session 的save() 、update() 、savaeOrUpdate() 、get() 或load() ,以及调用查询接口的list() 、iterate() 或filter() 方法时,如果在Session 缓存中还不存在相应的对象,hibernate配置文件中添加:
<property name="hibernate.cache.use_query_cache">true</property> <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
2.在要缓存的数据的实体配置文件中 添加:
<cache usage="read-only"/>
3.在查询dao中查询语句中添加
this.getHibernateTemplate().setCacheQueries(true);
4.添加ehcache.xml