Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Using redis as the secondary cache of mybatis

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

This paper introduces the configuration and application of using mybatis-redis project as the second-level cache of mybatis in production project.

First, add a dependency to pom:

Org.mybatis.caches mybatis-redis 1.0.0-beta2

After the dependency is added successfully, create the configuration file redis.properties for redis under src/main/resources

# 1.0 redis factory configuration

Host=xxx.xxx.xxx.xxx

Port=6379

Password=xxxxxxxx

Timeout=5000

UsePool=true

# redis pool configuration

MaxTotal=600

MaxIdle=300

MinIdle=10

MaxWaitMillis=2000

TestOnBorrow=false

TestOnReturn=false

After the configuration file is created successfully, write the configuration in between in the generated xxxMapper.xml

UseCache indicates whether caching is required

FlushCache indicates whether the cache needs to be flushed after insertion.

The test code is as follows. Refresh the cache synchronously after update and use the default configuration.

@ Testpublic void test01 () {Vc3JourneyAttributeDefinitions vc3JourneyAttributeDefinitions=new Vc3JourneyAttributeDefinitions (); vc3JourneyAttributeDefinitions=vc3JourneyAttributeDefinitionsMapper.selectByPrimaryKey (1L); vc3JourneyAttributeDefinitions.setAttributeName ("Total distance of valid pulses"); vc3JourneyAttributeDefinitionsMapper.updateByPrimaryKey (vc3JourneyAttributeDefinitions); vc3JourneyAttributeDefinitions=vc3JourneyAttributeDefinitionsMapper.selectByPrimaryKey (1L); System.out.println (vc3JourneyAttributeDefinitions.getAttributeName ());}

Https://github.com/mybatis/redis-cache from above github

You can download the source code to view.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report