cache and secondary cache mybatis

Cache : enabled by default

  1. MyBatis cache life cycle and SqlSession consistent.
  2. An internal cache MyBatis simple design, but without the HashMap defined capacity, lacking in functionality cache.
  3. MyBatis is the maximum range of an internal cache SqlSession, when a plurality of SqlSession or distributed environment, the database writes can cause dirty data,
  4. Dirty reason: to perform in a sqlSession several query operation, but in the middle of another sqlSession these query operations to update the database, and this update first sqlSession is no perception, at this time it is still a go inquiry query cache
  5. A cache miss (did not understand the reasons) using mybatis-spring

 

Secondary cache: off by default

      Life cycle namespace

  Step two cache Open: an open global cache (Setting enabled by default)

            Two in the corresponding opening in mapper.xml

  When the time sqlSession not closed or submit the data to the query does not cache secondary cache

  1. MyBatis secondary cache is a cache with respect to realized SqlSessionsharing of data between the cache, while more fine particle size, it is possible to namespacelevel, through the Cache interface class different combinations of controllability is also stronger Cache .
  2. MyBatis in multi-table queries, most likely will be dirty data (cache change a namespace in another namespace is not aware), there are design flaws, conditions for safe use of secondary cache relatively harsh appearance.
  3. In a distributed environment, due to the default implementation is based Cache MyBatis is bound under local, distributed environment appears to read dirty data, the cache will need to use a centralized interface Cache MyBatis, there are certain development costs, direct use Redis, Memcached distributed caching and other potentially lower cost, security is also higher

to sum up:

 

 

Guess you like

Origin www.cnblogs.com/zhaolei1996/p/12003835.html