Posted on 2009-11-02 14:43
瘋狂 閱讀(596)
評論(0) 編輯 收藏 所屬分類:
hibernate
步驟:
1:配置:
- <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
- <prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
2:bean配置:
寫道
@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
關(guān)于緩存策略介紹可見我的hibernate文章里面的相關(guān)內(nèi)容
3,查詢
- HibernateTemplate template = getHibernateTemplate();
- <SPAN style="COLOR: #ff0000">template.setCacheQueries(true);</SPAN>
- List list = template.loadAll(clazz);
HibernateTemplate template = getHibernateTemplate();
template.setCacheQueries(true);
List list = template.loadAll(clazz);
二級緩存需要和查詢緩存配合使用 查詢緩存緩存數(shù)據(jù)的id 并通過id去二級緩存查找