Cache and secondary cache mybatis

Cache  

        Mybatis level cache is a scope with SqlSession , in the same sqlSession executed twice in the same sql statement data for the first time will be finished in a database query written to the cache (memory), the second will get from the cache data will no longer be from the database query to improve query efficiency. When a sqlSession after the end of the sqlSession in the cache would not exist. Mybatis enabled by default cache.

 

simply say

 

         session level cache

   When a user on the same session when multiple queries, only one database query

   The query returns directly behind cached data

   When submitting a transaction ends session data in the cache will clear

Secondary cache

 

          Mybatis secondary cache is a plurality SqlSession shared, which scope is mapper same one namespace , different sqlSession performed twice same namespace in the sql statement and to sql passing the same parameters i.e., perform the same final sql statement of once finished will be a database query data is written to the cache (memory), the second gets the data from the cache will not be from a database query to improve query efficiency. Mybatis not enabled by default in the secondary cache requires setting configuration parameters enable a second global cache.

 

 

   The working principle is that when opened the second-level cache , the mybatis will cache data is serialized to disk

   When starting a new session when the query again tries to query from a second-level cache whether there is data,

   There are direct return data in the cache.

 

 

  Open second-level cache

 

 

 

 

 

 

 Increased need to open the secondary cache table mapping file  cache tag

 

 

 

  

 

 

Guess you like

Origin www.cnblogs.com/lin02/p/11469405.html