In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to achieve Mybatis first-level cache and second-level cache", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to achieve Mybatis first-level cache and second-level cache" this article.
Mybatis caching
Mybatis as a popular persistence tool, caching must be an indispensable component. Through this article, let's take a look at mybatis caching.
Mybatis cache type
Speaking of mybatis caching, all students know that there are two cache types in mybatis:
First, we often call it and caching, or sqlSession-level caching, which is included with mybatis. If the configuration in mapper is default, first-level caching is also enabled by default.
The second is non-sqlSession-level cache, which is commonly called secondary cache. Secondary cache in mybatis needs to implement the Cache API and is configured in mapper. To enable it first, some configuration is required, which we will talk about in detail below.
First-level cache
As the cache that comes with mybatis, let's analyze its principle through code.
First, let's look at the effect of the next level of caching.
Test the code:
@ Testpublic void test_Cache () throws Exception {InputStream input = Resources.getResourceAsStream ("mybatis-config.xml"); SqlSessionFactory factory = new SqlSessionFactoryBuilder () .build (input); SqlSession sqlSession = factory.openSession (); UserMapper mapper = sqlSession.getMapper (UserMapper.class); System.out.println ("the first query:"); mapper.queryAllUsers (); System.out.println ("= ="); System.out.println ("the second query:"); mapper.queryAllUsers () SqlSession.commit ();}
The mapper configuration is as follows, and we use the default configuration:
Select * from hwc_users
The running results are as follows:
Created connection 1191654595.
Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@470734c3]
= > Preparing: select * from hwc_users
= > Parameters:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.