Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring cache with instance variable and parameter as key

I am using ehcache for caching the method results. The key has to be a combination of both member object and method's parameter. My class looks something like:

Class A {

private B b;

@Cacheable(value="someCache",key="some key based on B and C")
public Result getResult(C c){
......
}

I need the key to be based on B and C. I referred https://code.google.com/p/ehcache-spring-annotations/issues/detail?id=69 but they did not specify how to include the method parameter in the key generation. Could someone help me with this?

like image 248
falcon Avatar asked Jun 27 '26 21:06

falcon


1 Answers

you can access the A object with root.target in the key. e.g.

key="#root.target.b.id+'-'+#c.id"
like image 180
cfrick Avatar answered Jun 29 '26 10:06

cfrick