Reputation: 11467
I'm using Spring Cache abstraction and a service with the following cache annotations.
Both methods will operate based on the id of the product as input parameter. However the return types are different. One is returning an Optional which might contact the product and the other returns a boolean.
@Cacheable(value = PRODUCTS_CACHE)
public Optional<Product> get(long id) {
return Optional.ofNullable(productRepository.findOne(id));
}
@Cacheable(value = PRODUCTS_CACHE)
public boolean exists(long id) {
return productRepository.exists(id);
}
1) Will this work as expected? 2) Is the Spring cache abstraction suitable for this?
Upvotes: 1
Views: 338
Reputation: 1251
You should use different caches or else it won't work. You could have used same cache with different key names, but as the method parameters are same, you have to again take help of SpEl for that.
Upvotes: 1