<select id="selectStudentById" resultType="student" parameterType="Integer" useCache="false"> select * from student where stuno=#{stuno} </select>
.2) Cleanup: Cleanup same buffer cache
. 1 SqlSession.close () will be recorded as a cache; (additions and deletions will perform a cache-busting; design reasons to produce dirty data)
<!-- https://mvnrepository.com/artifact/net.sf.ehcache/ehcache-core --> <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-core</artifactId> <version>2.6.11</version> </dependency> <!-- https://mvnrepository.com/artifact/org.mybatis.caches/mybatis-ehcache --> <dependency> <groupId>org.mybatis.caches</groupId> <artifactId>mybatis-ehcache</artifactId> <version>1.0.3</version> </dependency> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency>
2. Write ehcache.xml profile
<? Xml Version = "1.0" encoding = "UTF-8" ?> < Ehcache xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: noNamespaceSchemaLocation = "HTTP: // Ehcache .org / ehcache.xsd " UpdateCheck =" to false " > <-! when the secondary cache memory exceeds the limit of the object (the number of cache object> maxElementsInMemory) when the file is stored in the hard disk -> < diskStore path =" E : \ U \ Ehcache " /> <-! maxElementsInMemory: set the number of in-memory cache object maxElementsOnDisk: set the number of the hard disk cache object overflowToDisk: permanently set the cache does not expire diskPersistent:When the number of objects in-memory cache of more than maxElementsInMemory of metastasis to the hard disk When the number of objects in the cache memory exceeds maxElementsInMemory transferred to the hard disk whether timeToIdleSeconds: when access to more than twice this value, failure of the cache object timeToLiveSeconds: a cache object, most storage time (life cycle) diskExpiryThreadIntervalSeconds: How often to clean the cache hard disk by a thread in memoryStoreEvictionPolicy: strategy when the maximum cache object processing: LRU value is to delete the least used -> < defaultCache Eternal = "false" maxElementsOnDisk = "1000000 " maxElementsInMemory =" 1000 " overflowToDisk =" to false " diskPersistent =" to false " timeToIdleSeconds =" 100 " timeToLiveSeconds =" 100 " diskExpiryThreadIntervalSeconds =" 120 " memoryStoreEvictionPolicy =" the LRU " > </defaultCache> </ehcache>
3. Start the main secondary cache configuration
<! - opening the secondary cache -> < Setting name = "cacheEnabled" value = "to true" />
4. Write cache tag mapper
<! - declare open -> < Cache of the type = "org.mybatis.caches.ehcache.EhcacheCache" > <! - If you write the following values will override the global configuration of ehcache.xml -> <! - - <Property name = "maxElementsInMemory" value = "2000" /> -> <-! <Property name = "overflowToDisk" value = "to true" /> -> </ Cache >
5. Test mybatis comes with the same secondary cache