Ehcache is an open source Java distributed cache. Can be used with MyBatis first, create a new ehcache.xml content in the resource folder as follows:
1 <?XML version= "1.0" encoding= "UTF-8"?> 2 <EhcacheXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" 3 xsi:nonamespaceschemalocation=".. /bin/ehcache.xsd "> 4 <DefaultcacheOverflowtodisk= "true"Eternal= "false"maxelementsinmemory= "1"/> 5 <!--the path address needs to be modified in the production environment -6 <!--Dev -7 <DiskstorePath= "D:/cache" />8 <!--Product Linux -9 <!--<diskstore path= "XXX"/> -Ten </Ehcache>
Must be serialized in its own model, the serialization ID must be generated automatically (also in Redis)
Add the following ehcache to the Mapper.xml:
1 <!-- -2<!-- -3 <!-- -4 < type = " Org.mybatis.caches.ehcache.EhcacheCache "/>
The UseCache in the select expression is true by default, the cache is used, and if not, it is set to false.
After testing, the first query will have the output of SQL, the second start of the same query is not
Cache files on the hard disk
Ehcache one or two things-simple configuration application of Ehcashe in SSM