Guava: Cache stats always zero

Created on 31 Oct 2014  路  3Comments  路  Source: google/guava

_Original issue created by [email protected] on 2013-09-16 at 10:22 AM_


i 'm building a cache using LoadingCache

 dataCache = CacheBuilder.newBuilder().expireAfterWrite(600, TimeUnit.MINUTES)
                .maximumSize(SystemInfoLocal.CACHE_SIZE)
                .build(new CacheLoader<String, String[]>() {
                    @锘縊verride
                    public String[] load(String queryKey) throws Exception {
                        return getDataByKey(queryKey);
                    }
                });

but when I try to get CacheStat object ( by call toString method )

dataCache.stats().toString();

always retrieved this:

CacheStats{hitCount=0, missCount=0, loadSuccessCount=0,loadExceptionCount=0,totalLoadTime=0, evictionCount=0}

package=cache status=working-as-intended

Most helpful comment

_Original comment posted by stephan202 on 2013-09-16 at 11:15 AM_


This is because you did not call #recordStats() on the CacheBuilder. By default gathering of statistics is disabled. (In which case the EMPTY_STATS object is returned.)

All 3 comments

_Original comment posted by stephan202 on 2013-09-16 at 11:15 AM_


This is because you did not call #recordStats() on the CacheBuilder. By default gathering of statistics is disabled. (In which case the EMPTY_STATS object is returned.)

_Original comment posted by [email protected] on 2013-09-16 at 11:23 AM_


thanks for your helping , it's working :D

_Original comment posted by [email protected] on 2013-09-16 at 11:24 AM_


_(No comment entered for this change.)_


Status: WorkingAsIntended

Was this page helpful?
0 / 5 - 0 ratings