Spring Caching key generator - Stack Overflow
When things get more complicated SpEL perhaps is not the ideal solution when it comes to easy comprehension of the algorithm used to generate the key. You might consider to use Java for generating the key:
@Component public class FooGenerator implements KeyGenerator { @Override public Object generate(Object target, Method method, Object... params) { String param = ""; if (params.length == 2) { if (params[0] instanceof String) { param = (String) params[0]; String key = "FooKeyEquatesTo" + param; return key; }
Then you can wire in this keygenerator where you need it:
@Cacheable(value = "nameofmycachearea", keyGenerator="fooGenerator")
Read full article from Spring Caching key generator - Stack Overflow
No comments:
Post a Comment