mybatis cache

Level 1 cache: is the local cache, scope: sqlSession. When a Session is flushed or closed, all Caches in the Session will be emptied. But cannot be closed.
The first level cache of Mybatis refers to SqlSession. The scope of the first level cache is a SqlSession. Mybatis turns on the first level cache by default.

In the same SqlSession, the same query SQL is executed, the first time it will query the database and write it to the cache; the second time it will be directly fetched from the cache. When an addition, deletion or modification occurs between two queries when executing SQL, the cache of the SqlSession is cleared.

The second level cache of Mybatis: refers to the mapper mapping file. The scope of the second-level cache is the mapper mapping file content under the same namespace, which is shared by multiple SqlSessions. Mybatis needs to manually set up the second level cache. In the mapper file under the same namespace, the same query SQL is executed. The first time it will query the database and write it to the cache; the second time it will be taken directly from the cache. When an addition, deletion or modification occurs between two queries when executing SQL, the second-level cache is emptied.
The second-level cache is the collection of SQL queried in the first-level cache.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325200032&siteId=291194637