Listen to Geek College notes
Using the MyBatis cache requires the following three steps
First, open the cache in config. mybatis
<settings>
<setting name= "cacheenabled" value= "true"/>
</settings>
Second, specify the use of caching in the mapper header
<cache readonly= "false" size= "$" flushinterval= "120000" eviction= "LRU" ></cache>
ReadOnly true to return the same object for all the same SQL statements, which can help improve performance, but may not be secure when concurrently manipulating the same data, and if set to False then the same SQL accesses the clone copy of the cache.
Size caches the number of objects, the default value of 1024.
Flushinterval cache expiration, in milliseconds (1s=1000ms), is empty by default and will never expire as long as the capacity is sufficient.
Eviction is a cache culling algorithm with an optional value of "LRU", "FIFO", "SOFT", "WEAK", and the default value is LRU
LRU is least recently used to remove objects that are not used for the longest time.
FIFO advanced First out.
Soft soft references, which remove objects based on the garbage collector state and soft reference rules.
Weak weak references, based on garbage collector state and weak reference rules
Third, in the specific SQL to specify the use of the cache, the default open
<select id= "GetRowCount" resulttype= "int" usecache= "true" >
Java Learning-mybatis Cache policy