I have a random issue with CaffeineCache
in my Spring Boot application. The problem is with an integration test that makes next
- find user
- delete it
- find it again
It seems that sometimes cache doesn't not refreshes on time before the second call of find
that comes immediately after delete.
Here is a simplified signature of find
method
@Cacheable(cacheNames = "name", key = "{#config.id, #userId}", unless = "#result == null")
public User find(SomeConfig config, String userId) {
// ...
}
And a simplified signature of delete
@Caching(put = {
@CachePut(cacheNames = "someOtherCache", key = "#userId.technicalId"),
@CachePut(cacheNames = "name", key = "{#config.id, #userId}")
})
public User delete(SomeConfig config, String userId) {
// ...
}
I suppose that after call delete
cache is not updated immediately and that's why method find
is not called the second time. It happens 1 times from 10.
Any ideas about fix?