MyBatis Cache configuration
MyBatis provides first-level cache and second-level cache
Configure global configuration description default value cacheEnabled global cache switch truetrue falselocalCacheScope local cache, SESSION indicates that the executed sql result cache data can be shared in the same sqlSession
STATEMENT, on the other hand, is the same only if a single statement is cached
Two statements cannot share cache data SESSIONSESSION STATEMENT Mapper configuration flushCache=true represents the execution result of the statement, empties the local cache and level 2 cache useCache= "true" indicates the execution result of the statement, and is cached to the default value of level 2 cache: current Mapper cache configuration, secondary cache: cache is only used for a specific Namespace, that is, each namespace uses one cache instance, if multiple namespace use the same cache instance You can use cache-ref to refer to the cache configuration attribute to indicate the default value eviction reclaim memory policy LRULRU FIFO SOFT WEAKflushInterval refresh interval is not set greater than 0 (in ms) the number of size cache objects 1024 is greater than 0readOnly if true returns all callers to the same instance, although the performance is improved
But the program is required to ensure that the instance object is not modified, if it is false
Is read-write cache, and a Copy of the cached object is returned by serialization
Slower, but safer falsetrue falsetype can specify a custom cache, but this class must implement the
Org.apache.ibatis.cache.Cache interface
Com....class customizes the overall management structure of secondary cache:
MapperA.xml
MapperB.xml
MapperC.xml
As follows: