I have a Guava cache created with expireAfterWrite(20, TimeUnit.MINUTES)
. The cache is also initialized with dozens of entries when created. When values expire, client is supposed to call an external service and refresh the cache.
Problem is - all the initialized values would expire simultaneously and after 20 minutes, and the client would call the service dozens of times almost at the same instance.
I don't want this to happen. To avoid this - one idea is to probabilistically expire the entries a little earlier than the TTL so that the service won't get hit a lot at the same time.
Unfortunately, I don't see an option of doing this with Guava cache - at least nothing popped up from the Wiki or Javadoc. Is there any other library available? I am trying to avoid writing my own implementation of a cache for this purpose.