In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "@ CacheEvict can't solve how to clear the paging cache". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
@ CacheEvict cannot resolve paging cache cleanup
At present, the popular spring cache is encache, but recently, when I was writing a graduation project, I found that when caching paging, only one page of data was cached, resulting in no response when I clicked on the next page. So it took a while to get to know @ CacheEvict.
When we cache a data, it is cached in a key, as follows
/ / when inserting, you need to clear the contents of the cache key @ CacheEvict (value = "aboutShop", key = "'selectAllShop'") / / at the beginning of the query, the content saved to key @ Cacheable (value = "aboutShop", key = "' selectAllShop'") / / this is the cache key setting that was later added for paging, so that the cache is paged, but at the time of insertion. Unable to update to query information @ Cacheable (value = "aboutShop", key = "'selectAllShop_'+#params.pageNo")
This is one of my query pagination and cache paging at the beginning of the writing, however, each time the cache caches the first page
So, I went to see how to solve the problem.
Learned two ways of writing:
The first is to loop through and delete all content with the prefix selectAllShop in the way of spring AOP.
Because encache does not have its own fuzzy wildcards, you have to rewrite a method for matching deletion. Here is a blogger who speaks very well, and this is how I learned from my first method.
Https://www.yisu.com/article/134394.htm
Next, let's talk about the second method that I absorbed and used in the graduation project. After looking at the first method, I found that it takes a lot of time to iterate through deletion if there are hundreds of thousands of pieces of data (although I only have more than 100 pieces of data). So we can start with the familiar value of encache annotations.
The code I give is the custom value name I wrote. The configuration is greater than the convention. I configure a RedisCacheManager manager in spring-redis.xml and configure the cache range.
AboutUser aboutShop// this is my independent cache range, which is used to store the paging information of Shop queries.
Use when inserting information:
/ / allentries means to clear all the contents of value @ CacheEvict (value = "aboutShop", allEntries = true)
In this way, you can synchronize cache paging when inserting.
Spring paging cache @ Cacheable (key = "'myPage_'+#pagePlus.current+'_'+#pagePlus.limit") public void cachePage (Page pagePlus) {} "@ CacheEvict can't solve what to do with paging cache cleanup" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.