Reputation: 21
Is it possible to use the non constant fields or properties of current class in key of the @CacheEvict
annotation? For example:
public class Feature {
private int id;
@Autowired
private FeaturesClient featuresClient;
@CacheEvict(value = CacheConfiguration.FEATURES, key =
"T(java.lang.String).valueOf(#userId).concat(T(java.lang.String)" +
".valueOf( **#id** ))")
public boolean isFeatureAvailable(long userId) {
return featuresClient.isFeatureAvailable(userId, id);
}
}
Upvotes: 2
Views: 475
Reputation: 38777
Yes.
@CacheEvict(key = "#userId + #root.target.id")
#root.method
,#root.target
, and#root.caches
for references to the method, target object, and affected cache(s) respectively.
Upvotes: 1