Mybatis of Mybatis of cache

Mybatis have primary and secondary cache, enabled by default only one cache, L2 cache need to manually configure open.

mybatis level cache:

  • If in the same session, the query data id = 1, query twice, the mybatis will launch a SQL statement, this is the first-level cache.
  • When the session cache for each session independent of each other, a session cache does not affect the other.
  • If she had emptied session, the cache will disappear before
  • If you query the same data in the middle of the two, and the operation of the data additions and deletions of, mybatis will launch two SQL statements, because, additions and deletions to make mybatis automatically refresh the cache.         

mybatis secondary cache:

  •  Secondary cache, also known as global cache, which is based on namespace-level cache, a name space corresponds to a second-level cache, that is generally the same below a mapping file query share a common secondary cache space.
  • Next level cache along with the life cycle of a session and closed session of empty, open secondary cache, the cache where the data will be submitted before the emptying or secondary cache dump space continue to exist. Note: If there are two cache at the same time, through a session query the data id = 1, and this session is not closed, took advantage of another session to a query, it will also launch two SQL statements, because the cache is not closed Therefore, there is no data in the secondary cache  .
  • CRUD operations will also affect the secondary cache, the cache will refresh           

   Secondary cache of open

  • cacheEnabled set in the global configuration file configuration variable to true.
  • In the corresponding mapping file configuration <cache /> tag, indicates that the cache enable a second namespace
  • Serialization Serializable interfaces corresponding POJO
        select tag has a property to the useCache , the default is true, it may be set to false, then select the current secondary cache off
Published 40 original articles · won praise 25 · views 50000 +

Guess you like

Origin blog.csdn.net/wuud__/article/details/104345524