Here is the main introduction of Ehcache related configuration, spring and mybaits configuration here is just a brief introduction
1. Project Catalogue structure Display
2. jar package required by Ehcache
Spring-context-support-3.2.7.release.jar Spring's package is primarily used to support some other frameworks, so it is necessary to add, spring and mybaits some other jar packages to import as needed
3. Add ehcache.xml file in src directory
<?XML version= "1.0" encoding= "UTF-8"?><EhcacheXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:nonamespaceschemalocation= "Http://ehcache.org/ehcache.xsd"> <!--Default Cache - <Defaultcachemaxelementsinmemory= "+"Eternal= "false"Timetoidleseconds= "+"Timetoliveseconds= "+"Overflowtodisk= "false"/> <!--Specify the name cache cache - <Cachename= "Studycache"maxelementsinmemory= "+"Eternal= "false"Timetoidleseconds= "+"Timetoliveseconds= "+"Overflowtodisk= "false"Memorystoreevictionpolicy= "LRU"/> </Ehcache>
4. Join Ehcache related configuration In spring config file applicationcontext.xml
<Cache:annotation-drivenCache-manager= "CacheManager"/> <BeanID= "Cachemanagerfactory"class= "Org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> < Propertyname= "Configlocation"value= "Classpath:ehcache.xml" /> </Bean> <BeanID= "CacheManager"class= "Org.springframework.cache.ehcache.EhCacheCacheManager"> < Propertyname= "CacheManager"ref= "Cachemanagerfactory"/> </Bean>
5, need to cache the method before adding Ehcache annotations
@Cacheable (value= "Studycache") public list<tradeblotter> qrytradeblotterlist ( String Appno, String opid,string Fundacct, String fundid) { return Apptradeblotterdao.selecttradeblotterlist (Appno, Opid, Fundacct, Fundid); }
Ehcache Study Summary II: EHCACHE+SPRING+MYBAITS integration