Reputation: 119
I am using spring. I want to cache following method:
@Cacheable(cacheName = "xxx", key = "'foo_'.concat(#va1)")
public void foo(String var1, List<String> var2) { ... }
I want to include the value set of var2 into cache key. I know
key = "'foo_'.concat(#va1).concat('_').concat(#var2)"
is wrong. (Because (#var2)
will return its memory address, not values).
What should I do?
Upvotes: 0
Views: 872
Reputation: 1361
You could get the hashCode of the List:
key = "'foo_'.concat(#va1).concat('_').concat(#var2.hashCode())"
OR
key = "'foo_'.concat(#va1).concat('_').concat(#var2.toString())"
give it a try.
With the second one you are risking that your key might get to long according to the size of the list.
Upvotes: 1