Ehcache: two things
Ehcache is an open source Java distributed cache. You can use it with mybatis. First, create an ehcache. xml file in the resource folder as follows:
1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <ehcache xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" 3 xsi: noNamespaceSchemaLocation = ".. /bin/ehcache. xsd "> 4 <defaultCache overflowToDisk =" true "eternal =" false "maxElementsInMemory =" 1 "/> 5 <! -- Modify the path address in the production environment --> 6 <! -- Dev --> 7 <diskStore path = "D:/cache"/> 8 <! -- Product linux --> 9 <! -- <DiskStore path = "XXX"/> --> 10 </ehcache>
Serialization is required in your own model, and serialization ID must be automatically generated (this is also done in redis)
Add the following ehcache to mapper. xml:
1 <! -- Output log --> 2 <! -- <Cache type = "org. mybatis. caches. ehcache. LoggingEhcache"/> --> 3 <! -- Do not output logs --> 4 <cache type = "org. mybatis. caches. ehcache. EhcacheCache"/>
The useCache in the select expression is true by default, and the cache will be used. If you do not need it, set it to false.
After testing, the first query has SQL output, and the second query does not
Cached files on Hard Disk