I am trying to use the Spring @Cacheable annotation.
@Cacheable(value="users")
public List<User> findAll() {
System.out.println("Looking for All users : ");
return userRepository.findAll();
}
@Override
@Cacheable(value="users")
public User findOne(String userId) {
System.out.println("Looking for user : "+ userId);
return userRepository.findById(userId).get();
}
When I execute the first methode List<User>
I get :
- 1st time : select all fields from DataBase
- 2nd time : select all fields from Cache
- 3rd time : select all fields from Cache
Which is good till now.
When I execute the second method findOne(String userId)
I get the result from :
- 1st time : select specific field from DataBase
- 2nd time : select specific field from Cache
- 3rd time : select specific field from Cache
Which is good again.
When I execute the first methode List<User>
I get :
select all fields Data from Cache
Question : How the both methods (List<User>
and findOne(String userId)
had the same cache name but they return different result.