
Originally Posted by
Marten Deinum
Have you read the (java)docs for @Cacheable? key is an expression (SpEL) so you can basically select what you want/use as a key by writing the correct expression...
Of course I did. I managed to solve it by writing expressions like author.hashCode() + 31 * title.hashCode() or separating it into a helper function
Code:
public static int hashes(Object... args) {
return java.util.Arrays(args).asList().hashCode();
}
and calling it like key="T(mypackage.MyHelperClass).hashes(author, title)".
Thinking about it, maybe a better solution would be to use a list instead of working with hash codes (I'd have to check if it works):
Code:
public static int list(Object... args) {
return java.util.Arrays(args).asList();
}
and calling it like key="T(mypackage.MyHelperClass).list(author, title)".
But all this is very far from elegant and readable. The simple fact that I want to use two fields as the key is buried under a lot of boilerplate code. Is there a simpler solution I'm missing?
Thanks,
Petr