1.导入ehcache包和ehcache.xml文件
2.在cfg.xml文件中配置ehcache的外部类eg:EhCacheProvider等
<peoperty cache.provider_class class=" " />
3.在hbm文件中开启二级缓存:
<cache usage="readonly(事务模式)" include="all/non-loazy" regin="在ehcache.xml文件中的配置策略(自定义名称)" />
4.在ehcache.xml文件中配置缓存策略,比如最多缓存的元素的大小,超时设置,生命周期等
<cache name="Employee"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true"
/>