In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to match and delete using @ CacheEvict multi-parameters". The content is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn how to use @ CacheEvict multi-parameters to match and delete this article.
@ CacheEvict Multi-parameter matching deletion
If @ Cacheable ("XXX")
Object getXXX (String a, String b, String c)
The key used by spring's cache is the ESPL expression, and then look at the source code key. The default generation method is org.springframework.cache.interceptor.SimpleKeyGenerator.
More than 1 parameter is the last method.
/ * Generate a key based on the specified parameters. * / public static Object generateKey (Object... Params) {if (params.length = = 0) {return SimpleKey.EMPTY;} if (params.length = = 1) {Object param = params [0]; if (param! = null & &! param.getClass (). IsArray ()) {return param;}} return new SimpleKey (params);}
Then look at the corresponding code of org.springframework.cache.interceptor.SimpleKey and find that what is returned is actually SimpleKey
/ * * Create a new {@ link SimpleKey} instance. * @ param elements the elements of the key * / public SimpleKey (Object... Elements) {Assert.notNull (elements, "Elements must not be null"); this.params = new Object [elements.length]; System.arraycopy (elements, 0, this.params, 0, elements.length); this.hashCode = Arrays.deepHashCode (this.params);} solution 1
Write a custom KeyGenerator separately to deal with the corresponding key. (the previous redis article has been written, so I won't repeat it.)
The MyKeyGenerator class of the following blog post
Sprintboot uses spring-security package, cache memory and redis coexist
Option 2 @ Cacheable (value= "XXX", key= "xxxx") @ CacheEvict (value= "XXX", key= "xxxx")
Make the corresponding key configuration
For an array, you can use key = "# root.args [0]"
The parameters are as follows:
Name location description sample methodNameroot object currently called method name # root.methodNamemethodroot object currently called method # root.method .nametargetroot object currently called target object # root.targettargetClassroot object currently called target object class # root.targetClassargsroot object currently called method parameter list # root.args [0] cachesroot object current method invocation cache list # root.caches [0] .nameargument nameevaluation context method parameter name You can directly # the parameter name, or you can use the form of # p0 or # a0. 0 represents the index of the parameter # iban, # a0, and the returned value after the execution of the # p0resultevaluation context method is more than # result. Thank you for reading all of the article "how to match and delete using @ CacheEvict multiple parameters". 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.