0

I am using LoadingCache in CaffeineCache. I set refreshAfterWrite to 30 minute and checked the stats by Caffeine.stats(). I expected the loadSuccessCount value will be increased after 30 minutes but it's as same as before 30 minutes.

Below is code:

        codeListCache = Caffeine.newBuilder()
            .refreshAfterWrite(30, TimeUnit.MINUTES)
            .recordStats()
            .build(codeFilterNo -> loadCodeList(codeFilterNo));

        codeListCache.getAll(codeFilterNoList);

Below is log which I was trying to check.


2020-04-13 00:13:42 [scheduling-1] INFO c.n.a.p.s.service.OlapTableService - CodeListCache Stats : CacheStats{hitCount=0, missCount=30, loadSuccessCount=30, loadFailureCount=0, totalLoadTime=2139529433, evictionCount=0, evictionWeight=0}

2020-04-13 01:08:42 [scheduling-1] INFO c.n.a.p.s.service.OlapTableService - CodeListCache Stats : CacheStats{hitCount=102, missCount=30, loadSuccessCount=30, loadFailureCount=0, totalLoadTime=2139529433, evictionCount=0, evictionWeight=0}


I can see the hitCount is growing but I'm not sure if the cache is reloaded successfully because the loadSuccessCount doesn't change. I thought that refreshAfterWrite will update the value per key 30 minutes after the last write and this would increase the 'loadSuccessCount'.

So my question is,

  • Can someone tell me if it is normal or a bug?

  • How can I check if the cache refresh work well?

  • The refresh will occur if the entry is accessed after 30 minutes, it doesn't reload it proactively when inactive. This is generally used with expiration to hide the latency when a popular entry expires. You can use Guava's `FakeTicker` to verify in a unit test. – Ben Manes Apr 14 '20 at 01:38
  • @BenManes Thank you for your comment. I think I misunderstood the usage of `refresh`. I will check `FakeTicker` and do the unit test. Thank you for your help! – Hongmin Park Apr 16 '20 at 02:04

0 Answers0