We are exploring options to use Ehcache for our web-application at two levels
- For Hibernate second level cache.
- For web-application cache (jsp)
now we have the following issue,we are developing kinda content management system so we will going to have a back-office where we will manage all the content and other things and another is the UI part.
for UI part i can configure the filters in such way that they will only cache the contents of the UI and no back office cache management.
but the real issue is for the Hibernate second level cache since we are planning to use same DAO layer for the UI part but since we need to configure the cache settings in the corresponding .hbm files which means cache will also work for the back-开发者_JAVA百科office which we want to avoid.
All we want that Hibernate second level cache should be activated for the UI parts and for back-office it should not come in to play but it does not seems feasible at the moment due to the use of same DAO layer but we don't want to duplicate the DAO code.
is there any way to achieve this.Any suggestion in this regard will be much helpful.
In your DAO, you'll need to add setCacheable(true) to your Query so basically you can just add a boolean parameter to your DAO method to pass to setCacheable(...)
Class YourDao {
public List loadStuff(Session session, boolean isCacheable) {
return session.createQuery("from Myentity").setCacheable(isCacheable).list();
}
}
精彩评论