In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use @ CachePut to update the database and update cache, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
About updating the cache, pay attention to two points: 1, @ Cacheable's key
To be consistent with @ CachePut's key
For example:
@ Cacheable (key = "'userCache'") / / cache, public Uuser findByEmail (String email) {System.err.println ("execute here, indicating that the data cannot be read in the cache, read the database directly."); return redisMapper.findByEmail (email) } @ CachePut (key = "'userCache'") / / userCache is to be enclosed in' 'single quotes, indicating that this is a string public Uuser updateSelf (String nickname, String email) {System.err.println ("execute here, update the database, update the cache."); uuserMapper.updateSelf (nickname, email); Uuser uuser = redisMapper.findByEmail (email); return values of return uuser;} 2 and @ CachePut
To be the same as the return value of @ Cacheable
If @ Cacheable returns an object, @ CachePut returns an object, otherwise it will report a type conversion exception, such as Uuser.
Cached CachePut conflict Cacheable
When CachePut and Cacheable are put together, Cacheable has the same effect as CachePut, checking the database every time, even though there is a cache.
/ * * @ param id * @ return * / @ Caching (put = {@ CachePut (key = "T (cn.a.b.constant.RedisKey). OPEN_MEDIUM_INFO + # result.mediumBankCard", unless= "# result.mediumBankCard==null or # result.status! ='2'"), @ CachePut (key = "T (a.b.c.constant.RedisKey). ACCOUNT_CODE + # result.accountCode", unless= "! '3'} .coach (# result.mediumStatus)), @ CachePut (key= "T (a.b.c.constant.RedisKey). CERT_NO+ # result.certNo", unless= "# result.certNo==null or! {' 0# result.status))}, cacheable = {@ Cacheable (key=" T (a.b.c.constant.RedisKey). ID + # id ") public XXXInfo selectByPrimaryKey (Long id) {return mapper.selectByPrimaryKey (id) } can be decomposed into two Service.java/** @ param id * @ return * / @ Caching (put = {@ CachePut (key = "T (cn.a.b.constant.RedisKey). OPEN_MEDIUM_INFO + # result.mediumBankCard", unless= "# result.mediumBankCard==null or # result.status! ='2'"), @ CachePut (key = "T (a.b.c.constant.RedisKey). ACCOUNT_CODE + # result.accountCode", unless= "! {'0' (# result.mediumStatus), @ CachePut (key = "T (a.b.c.constant.RedisKey). CERT_NO+ # result.certNo", unless= "# result.certNo==null or! {# result.status))}) public XXXInfo selectByPrimaryKey (Long id) {return mapper.selectByPrimaryKey (id)) } Mapper.java {@ Cacheable (key= "T (a.b.c.constant.RedisKey). ID + # p0") XXXXInfo selectByPrimaryKey (Long id);}
Mybatis interface class parameters. Invalid # parameter name. Can only use # p0, # p1
The above is all the contents of the article "how to use @ CachePut to update the database and update the cache". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.