Mybatis L2 cache implementation code
L2 cache needs to be manually configured and enabled, as follows:
Set enable L2 cache / mybatis02 / config / mybatis-conf.xml in the general configuration file
It's no use just opening this. You also need to open such a tag in each mapping XML file
/Mybatis02/config/mappers/GoodsInfoMapper. xml
No, there's a third step. Let our entity class (that is, javebean) implement a serialized interface
summary
2.1 set L2 cache on in the general configuration
/Mybatis02/config/mappers/GoodsInfoMapper. xml
/Mybatis02/src/test/Start2. java
Click Run
The second time, instead of fetching data from the cache, an SQL query is reissued. So what's the problem?
When a new sqlsession object uses the data in the L2 cache, it is necessary to close the previous sqlsession object before the data can enter the L2 cache
Click Run
This is the L2 cache. The first one has been closed. The second time, it reads the data in the L2 cache and does not reissue new SQL statements.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.