I have a simple service in a springboot application, one of the methods gets an object from the database by Id(Primary key). I also have another method that returns all the objects in that table.
@Cacheable("stores")
public List<Store> findAllStores() throws InterruptedException {
Thread.sleep(5000);
return storeRepository.findAll();
}
@Cacheable("stores")
public Store findById(int storeId) throws InterruptedException {
Thread.sleep(5000);
return storeRepository.findById(storeId).orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "No store with specified ID exist"));
}
In my tests I called the first method, which populated the cache called "stores" with all the store objects from the table, but when I call the second method to individually find a store by Id, i still get the 5 second wait time? Why is this happening? There are no errors and cache is not a variable so i'm finding it really hard to debug this problem, as I cant see the contents of the cache during debug session.