本文整理汇总了Java中com.google.common.cache.CacheStats类的典型用法代码示例。如果您正苦于以下问题:Java CacheStats类的具体用法?Java CacheStats怎么用?Java CacheStats使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CacheStats类属于com.google.common.cache包,在下文中一共展示了CacheStats类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCacheStats
import com.google.common.cache.CacheStats; //导入依赖的package包/类
/**
* Get the current WatchedByAttributeCache status. Returns the cumulative status of
* <ul>
* <li>hitCount
* <li>missCount;
* <li>loadSuccessCount;
* <li>loadExceptionCount;
* <li>totalLoadTime;
* <li>evictionCount;
* </ul>
*
* @return cache status map.
*/
@RequestMapping(value = "/cache/stats", method = RequestMethod.GET)
@ResponseBody
public Map<String, Object> getCacheStats() {
Map<String, Object> stat = new LinkedHashMap<>(5);
stat.put("status", "ok");
stat.put("maxSize", cache.getMaxSize());
stat.put("currentSize", cache.instance().size());
stat.put("timeout", cache.getTimeout());
CacheStats cs = cache.instance().stats();
stat.put("hitCount", cs.hitCount());
stat.put("missCount", cs.missCount());
stat.put("loadSuccessCount", cs.loadSuccessCount());
stat.put("totalLoadTime", TimeUnit.SECONDS.convert(cs.totalLoadTime(), TimeUnit.NANOSECONDS));
stat.put("loadExceptionCount", cs.loadExceptionCount());
stat.put("evictionCount", cs.evictionCount());
return stat;
}
示例2: getCacheStats
import com.google.common.cache.CacheStats; //导入依赖的package包/类
/**
* Get the current sink cache status. Returns the cumulative status of
* <ul>
* <li>hitCount
* <li>missCount;
* <li>loadSuccessCount;
* <li>loadExceptionCount;
* <li>totalLoadTime;
* <li>evictionCount;
* </ul>
*
* @return cache status map.
*/
@RequestMapping(value = "/cache/stats", method = GET)
@ResponseBody
public Map<String, Object> getCacheStats() {
Map<String, Object> stat = new LinkedHashMap<>(5);
stat.put("status", "ok");
stat.put("maxSize", cache.getMaxSize());
stat.put("currentSize", cache.instance().size());
stat.put("timeout", cache.getTimeout());
CacheStats cs = cache.instance().stats();
stat.put("hitCount", cs.hitCount());
stat.put("missCount", cs.missCount());
stat.put("loadSuccessCount", cs.loadSuccessCount());
stat.put("totalLoadTime", SECONDS.convert(cs.totalLoadTime(), NANOSECONDS));
stat.put("loadExceptionCount", cs.loadExceptionCount());
stat.put("evictionCount", cs.evictionCount());
return stat;
}
示例3: applyMetrics
import com.google.common.cache.CacheStats; //导入依赖的package包/类
@Override
public void applyMetrics(Map<String, Object> map) {
CacheStats stats = cache.stats();
map.put(prefix + "averageLoadPenalty", stats.averageLoadPenalty());
map.put(prefix + "evictionCount", stats.evictionCount());
map.put(prefix + "hitCount", stats.hitCount());
map.put(prefix + "hitRate", stats.hitRate());
map.put(prefix + "hitCount", stats.hitCount());
map.put(prefix + "loadExceptionCount", stats.loadExceptionCount());
map.put(prefix + "loadExceptionRate", stats.loadExceptionRate());
map.put(prefix + "loadSuccessCount", stats.loadSuccessCount());
map.put(prefix + "missCount", stats.missCount());
map.put(prefix + "missRate", stats.missRate());
map.put(prefix + "requestCount", stats.requestCount());
map.put(prefix + "totalLoadTime", stats.totalLoadTime());
}
示例4: test_reset
import com.google.common.cache.CacheStats; //导入依赖的package包/类
@Test
public void test_reset()
{
Assert.assertEquals("LoadedServicesCount", 0, Services.getLoadedServicesCount());
Services.get(IMockedSingletonService.class);
Assert.assertEquals("LoadedServicesCount", 1, Services.getLoadedServicesCount());
Services.clear();
Assert.assertEquals("LoadedServicesCount", 0, Services.getLoadedServicesCount());
//
// Check implementation specifics
final Cache<Class<? extends IService>, Object> servicesMap = getServicesInternalMap();
final CacheStats cacheStats = servicesMap.stats();
Assert.assertEquals("ServicesMap - size", 0, servicesMap.size());
Assert.assertEquals("ServicesMap - Stats - loadCount", 0, cacheStats.loadCount());
Assert.assertEquals("ServicesMap - Stats - hitCount", 0, cacheStats.hitCount());
Assert.assertEquals("ServicesMap - Stats - missCount", 0, cacheStats.missCount());
}
示例5: CacheInfo
import com.google.common.cache.CacheStats; //导入依赖的package包/类
public CacheInfo(String name, Cache<?, ?> cache) {
this.name = name;
CacheStats stat = cache.stats();
entries = new EntriesInfo();
entries.setMem(cache.size());
averageGet = duration(stat.averageLoadPenalty());
hitRatio = new HitRatioInfo();
hitRatio.setMem(stat.hitCount(), stat.requestCount());
if (cache instanceof PersistentCache) {
type = CacheType.DISK;
PersistentCache.DiskStats diskStats = ((PersistentCache) cache).diskStats();
entries.setDisk(diskStats.size());
entries.setSpace(diskStats.space());
hitRatio.setDisk(diskStats.hitCount(), diskStats.requestCount());
} else {
type = CacheType.MEM;
}
}
示例6: SchemaCache
import com.google.common.cache.CacheStats; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public SchemaCache(long versionAtCreation, CacheLimits limits, PreparedStatementPlanCache thePstmtCache) {
CacheSegment[] values = CacheSegment.values();
tloaded = (Cache<SchemaCacheKey<?>, Object>[]) Array.newInstance(Cache/*<SchemaCacheKey<?>,Object>*/.class, values.length);
tloaded_baseline = new CacheStats[values.length];
for(CacheSegment cs : values) {
if (cs == CacheSegment.PLAN)
continue;
tloaded[cs.ordinal()] = buildCache(limits.getLimit(cs));
tloaded_baseline[cs.ordinal()] = null;
}
planCache = new GlobalPlanCache(limits);
pstmtCache = thePstmtCache;
version = versionAtCreation;
}
示例7: stat
import com.google.common.cache.CacheStats; //导入依赖的package包/类
@Override
public void stat(){
if (STAT_ENABLED) {
CacheStats shortStats = shortTermCache.stats();
CacheStats longStats = longTermCache.stats();
System.out.println("--------- GUAVA CACHE Statistics ---------");
System.out.println("|>--- SHORT-TERM");
System.out.println("| Hits (count/rate): " + shortStats.hitCount() + " / "
+ String.format("%.2f%%", shortStats.hitRate() * 100));
System.out.println("| Misses (count/rate): " + shortStats.missCount() + " / "
+ String.format("%.2f%%", shortStats.missRate() * 100));
System.out.println("|>--- LONG-TERM ");
System.out.println("| Hits (count/rate): " + longStats.hitCount() + " / "
+ String.format("%.2f%%", longStats.hitRate() * 100));
System.out.println("| Misses (count/rate): " + longStats.missCount() + " / "
+ String.format("%.2f%%", longStats.missRate() * 100));
System.out.println("------------------------------------------");
}
}
示例8: buildStats
import com.google.common.cache.CacheStats; //导入依赖的package包/类
private Map<String, Object> buildStats(String name, Cache<Object, Object> cache) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("name", name);
map.put("status", "UP");
map.put("size", cache.size());
CacheStats stats = cache.stats();
map.put("hitRate", stats.hitRate());
map.put("hitCount", stats.hitCount());
map.put("missCount", stats.missRate());
map.put("loadSuccessCount", stats.loadSuccessCount());
map.put("loadExceptionCount", stats.loadExceptionCount());
map.put("totalLoadTime", stats.totalLoadTime());
map.put("evictionCount", stats.evictionCount());
return map;
}
示例9: getCacheStatus
import com.google.common.cache.CacheStats; //导入依赖的package包/类
/**
* Short description of the cache configuration for display in admin interface
* @return String containing all relevant configuration parameters.
*/
@Override
public String getCacheStatus() {
CacheStats stats = cache.stats();
return Objects.toStringHelper("Guava-CacheStats")
.add("size", cache.size())
.add("hitCount", stats.hitCount())
.add("missCount", stats.missCount())
.add("loadSuccessCount", stats.loadSuccessCount())
.add("loadExceptionCount", stats.loadExceptionCount())
.add("totalLoadTime", stats.totalLoadTime())
.add("evictionCount", stats.evictionCount())
.toString();
}
示例10: clear
import com.google.common.cache.CacheStats; //导入依赖的package包/类
@Override
public void clear()
{
CacheStats cacheStats = cache.unwrap(GuavaCache.class).stats();
snapshot =
new CacheStats(cacheStats.hitCount(),
cacheStats.missCount(),
cacheStats.loadSuccessCount(),
cacheStats.loadExceptionCount(),
cacheStats.totalLoadTime(),
cacheStats.evictionCount());
}
示例11: getCacheStatistics
import com.google.common.cache.CacheStats; //导入依赖的package包/类
@Override
public CacheStatistics getCacheStatistics(CacheManager cacheManager,
GuavaCache cache) {
DefaultCacheStatistics statistics = new DefaultCacheStatistics();
statistics.setSize(cache.getNativeCache().size());
CacheStats guavaStats = cache.getNativeCache().stats();
if (guavaStats.requestCount() > 0) {
statistics.setHitRatio(guavaStats.hitRate());
statistics.setMissRatio(guavaStats.missRate());
}
return statistics;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:GuavaCacheStatisticsProvider.java
示例12: afterPropertiesSet
import com.google.common.cache.CacheStats; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
configDir = new File(configDirName).getAbsoluteFile();
appDir = new File(appDirName).getAbsoluteFile();
if(!configDir.isDirectory()) throw new IllegalArgumentException("The configuration directory [" + configDirName + "] is invalid");
if(!appDir.exists()) {
appDir.mkdirs();
}
if(!appDir.isDirectory()) throw new IllegalArgumentException("The app directory [" + appDirName + "] is invalid");
log.info("Configuration Directory: [{}]", configDir);
if(!cacheSpec.contains("recordStats")) cacheSpec = cacheSpec + ",recordStats";
configCache = CacheBuilder.from(cacheSpec).build(configCacheLoader);
configCacheStats = new CachedGauge<CacheStats>(5, TimeUnit.SECONDS) {
@Override
protected CacheStats loadValue() {
return configCache.stats();
}
};
appJarCache = CacheBuilder.from(cacheSpec).build(appJarCacheLoader);
appJarCacheStats = new CachedGauge<CacheStats>(5, TimeUnit.SECONDS) {
@Override
protected CacheStats loadValue() {
return appJarCache.stats();
}
};
reloadConfigCache();
log.info("Loaded [{}] App Configurations", configCache.size());
reloadAppJarCache();
log.info("Loaded [{}] App Jar Sets", appJarCache.size());
}
示例13: testGetCacheStats
import com.google.common.cache.CacheStats; //导入依赖的package包/类
@Test
public void testGetCacheStats() throws Exception {
TradeAccount expectedTradeAccount = new TradeAccount.Builder().build();
when(cacheLoader.load("223")).thenReturn(expectedTradeAccount);
when(cacheLoader.load("000")).thenThrow(new RuntimeException("Bad Value"));
LoadingCache<String, TradeAccount> tradeAccountCache = CacheBuilder.newBuilder()
.maximumSize(5000L)
.expireAfterAccess(10l, TimeUnit.MILLISECONDS)
.recordStats()
.build(cacheLoader);
TradeAccount tradeAccount = tradeAccountCache.get("223");
assertThat(tradeAccount, is(expectedTradeAccount));
TradeAccount tradeAccount1 = tradeAccountCache.get("223");
assertThat(tradeAccount1, is(expectedTradeAccount));
Thread.sleep(20);
TradeAccount tradeAccount2 = tradeAccountCache.get("223");
assertThat(tradeAccount2, is(expectedTradeAccount));
try{
tradeAccountCache.get("000");
}catch (RuntimeException e){
//Ignore expected
}
CacheStats stats = tradeAccountCache.stats();
assertThat(stats.evictionCount(),is(1l));
assertThat(stats.hitCount(),is(1l));
assertThat(stats.missCount(),is(3l));
assertThat(stats.hitRate(),is((double)1/4));
assertThat(stats.loadExceptionCount(),is(1l));
assertThat(stats.loadExceptionRate(),is((double)1/3));
assertThat(stats.loadSuccessCount(),is(2l));
verify(cacheLoader, times(2)).load("223");
}
示例14: ClientStats
import com.google.common.cache.CacheStats; //导入依赖的package包/类
/** Package-private constructor. */
ClientStats(final long num_connections_created,
final long root_lookups,
final long meta_lookups_with_permit,
final long meta_lookups_wo_permit,
final long num_flushes,
final long num_nsres,
final long num_nsre_rpcs,
final long num_multi_rpcs,
final long num_gets,
final long num_scanners_opened,
final long num_scans,
final long num_puts,
final long num_appends,
final long num_row_locks,
final long num_deletes,
final long num_atomic_increments,
final CacheStats increment_buffer_stats) {
// JAVA Y U NO HAVE CASE CLASS LIKE SCALA?! FFFFFUUUUUUU!!
this.num_connections_created = num_connections_created;
this.root_lookups = root_lookups;
this.meta_lookups_with_permit = meta_lookups_with_permit;
this.meta_lookups_wo_permit = meta_lookups_wo_permit;
this.num_flushes = num_flushes;
this.num_nsres = num_nsres;
this.num_nsre_rpcs = num_nsre_rpcs;
this.num_multi_rpcs = num_multi_rpcs;
this.num_gets = num_gets;
this.num_scanners_opened = num_scanners_opened;
this.num_scans = num_scans;
this.num_puts = num_puts;
this.num_appends = num_appends;
this.num_row_locks = num_row_locks;
this.num_deletes = num_deletes;
this.num_atomic_increments = num_atomic_increments;
this.increment_buffer_stats = increment_buffer_stats;
}
示例15: readFrom
import com.google.common.cache.CacheStats; //导入依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
size = in.readVLong();
long hitCount = in.readVLong();
long misscount = in.readVLong();
long loadSuccessCount = in.readVLong();
long loadExceptionCount = in.readVLong();
long totalLoadTime = in.readVLong();
long evictionCount = in.readVLong();
cacheStats = new CacheStats(hitCount, misscount, loadSuccessCount, loadExceptionCount, totalLoadTime, evictionCount);
}