net.sf.ehcache.Cache.getStatistics()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(214)

本文整理了Java中net.sf.ehcache.Cache.getStatistics()方法的一些代码示例,展示了Cache.getStatistics()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.getStatistics()方法的具体详情如下:
包路径:net.sf.ehcache.Cache
类名称:Cache
方法名:getStatistics

Cache.getStatistics介绍

[英]Note, the #getSize method will have the same value as the size reported by Statistics for the statistics accuracy of Statistics#STATISTICS_ACCURACY_BEST_EFFORT.
[中]注意,#getSize方法将具有与统计报告的大小相同的值,用于统计的统计准确性#统计的准确性#最佳努力。

代码示例

代码示例来源:origin: gocd/gocd

public Map<String, Object> getCacheRuntimeInformationAsJson(Cache cache) {
  LinkedHashMap<String, Object> json = new LinkedHashMap<>();
  StatisticsGateway statistics = cache.getStatistics();
  json.put("Get Time in milliseconds", getStatisticsFrom(statistics.cacheGetOperation()));
  json.put("Put Time in milliseconds", getStatisticsFrom(statistics.cachePutOperation()));
  json.put("Remove Time in milliseconds", getStatisticsFrom(statistics.cacheRemoveOperation()));
  json.put("Cache Size", statistics.getSize());
  LinkedHashMap<String, Long> cacheCount = new LinkedHashMap<>();
  cacheCount.put("Hits", statistics.cacheHitCount());
  cacheCount.put("Miss", statistics.cacheMissCount());
  cacheCount.put("Expired", statistics.cacheExpiredCount());
  cacheCount.put("Eviction", statistics.cacheEvictedCount());
  cacheCount.put("Put", statistics.cachePutCount());
  cacheCount.put("Remove", statistics.cacheRemoveCount());
  json.put("Cache Counts", cacheCount);
  json.put("Cache Size (Disk)", statistics.getLocalDiskSize());
  json.put("Cache Count (Disk)", statistics.localDiskHitCount());
  return json;
}

代码示例来源:origin: apache/kylin

System.out.println(testCache.get("1") == null);
System.out.println(testCache.getSize());
System.out.println(testCache.getStatistics().getLocalHeapSizeInBytes());
System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M");
System.out.println(testCache.get("2") == null);
System.out.println(testCache.getSize());
System.out.println(testCache.getStatistics().getLocalHeapSizeInBytes());
System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M");
System.out.println(testCache.get("3") == null);
System.out.println(testCache.getSize());
System.out.println(testCache.getStatistics().getLocalHeapSizeInBytes());
System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M");

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 *
 * @see net.sf.ehcache.hibernate.management.api.EhcacheStats#getNumberOfElementsOnDisk(java.lang.String)
 */
public int getNumberOfElementsOnDisk(String region) {
  Cache cache = this.cacheManager.getCache(region);
  if (cache != null) {
    return (int) cache.getStatistics().getLocalDiskSize();
  } else {
    return -1;
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 *
 * @see net.sf.ehcache.hibernate.management.api.EhcacheStats#getNumberOfElementsInMemory(java.lang.String)
 */
public int getNumberOfElementsInMemory(String region) {
  Cache cache = this.cacheManager.getCache(region);
  if (cache != null) {
    return (int) cache.getStatistics().getLocalHeapSize();
  } else {
    return -1;
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 *
 * @see net.sf.ehcache.hibernate.management.api.EhcacheStats#getNumberOfElementsOffHeap(java.lang.String)
 */
public int getNumberOfElementsOffHeap(String region) {
  Cache cache = this.cacheManager.getCache(region);
  if (cache != null) {
    return (int) cache.getStatistics().getLocalOffHeapSize();
  } else {
    return -1;
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Gets the size of the off-heap store for this cache.
 *
 * @return the size of the off-heap store in bytes
 * @throws IllegalStateException if the cache is not {@link Status#STATUS_ALIVE}
 */
@Deprecated public final long calculateOffHeapSize() throws IllegalStateException, CacheException {
  checkStatus();
  return getStatistics().getLocalOffHeapSizeInBytes();
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Gets the size of the on-disk store for this cache
 *
 * @return the size of the on-disk store in bytes
 * @throws IllegalStateException if the cache is not {@link Status#STATUS_ALIVE}
 */
@Deprecated public final long calculateOnDiskSize() throws IllegalStateException, CacheException {
  checkStatus();
  return getStatistics().getLocalDiskSizeInBytes();
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Returns the number of elements in the off-heap store.
 *
 * @return the number of elements in the off-heap store
 * @throws IllegalStateException if the cache is not {@link Status#STATUS_ALIVE}
 */
@Deprecated public long getOffHeapStoreSize() throws IllegalStateException {
  checkStatus();
  return getStatistics().getLocalOffHeapSize();
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Returns the number of elements in the memory store.
 *
 * @return the number of elements in the memory store
 * @throws IllegalStateException if the cache is not {@link Status#STATUS_ALIVE}
 */
@Deprecated public final long getMemoryStoreSize() throws IllegalStateException {
  checkStatus();
  return getStatistics().getLocalHeapSize();
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 */
public long getCacheMissCount() {
  long count = 0;
  for (String name : cacheManager.getCacheNames()) {
    Cache cache = cacheManager.getCache(name);
    if (cache != null) {
      count += cache.getStatistics().cacheMissCount();
    }
  }
  return count;
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 */
public long getCachePutCount() {
  long count = 0;
  for (String name : cacheManager.getCacheNames()) {
    Cache cache = cacheManager.getCache(name);
    if (cache != null) {
      count += cache.getStatistics().cachePutCount();
    }
  }
  return count;
}

代码示例来源:origin: banq/jdonframework

public long getCacheMisses() {
  Cache cache = manager.getCache(ehcacheConf.getPredefinedCacheName());
  return cache.getStatistics().getCacheMisses();
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 */
public long getCacheHitCount() {
  long count = 0;
  for (String name : cacheManager.getCacheNames()) {
    Cache cache = cacheManager.getCache(name);
    if (cache != null) {
      count += cache.getStatistics().cacheHitCount();
    }
  }
  return count;
}

代码示例来源:origin: banq/jdonframework

public long getCacheHits() {
  Cache cache = manager.getCache(ehcacheConf.getPredefinedCacheName());
  return cache.getStatistics().getCacheHits();
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 *
 * @see net.sf.ehcache.hibernate.management.api.EhcacheStats#getMaxGetTimeMillis(java.lang.String)
 */
public long getMaxGetTimeMillis(String cacheName) {
  Cache cache = cacheManager.getCache(cacheName);
  if (cache != null) {
    return TimeUnit.MILLISECONDS.convert(cache.getStatistics().cacheGetOperation().latency().maximum().value().longValue(),
        TimeUnit.NANOSECONDS);
  } else {
    return 0;
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 *
 * @see net.sf.ehcache.hibernate.management.api.EhcacheStats#getMinGetTimeMillis(java.lang.String)
 */
public long getMinGetTimeMillis(String cacheName) {
  Cache cache = cacheManager.getCache(cacheName);
  if (cache != null) {
    return TimeUnit.MILLISECONDS.convert(cache.getStatistics().cacheGetOperation().latency().minimum().value().longValue(),
        TimeUnit.NANOSECONDS);
  } else {
    return 0;
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 */
public long getMaxGetTimeMillis() {
  long rv = 0;
  for (String cacheName : cacheManager.getCacheNames()) {
    Cache cache = cacheManager.getCache(cacheName);
    if (cache != null) {
      rv = Math.max(rv, TimeUnit.MILLISECONDS.convert(cache.getStatistics().cacheSearchOperation().latency().maximum().value().longValue(),
          TimeUnit.NANOSECONDS));
    }
  }
  return rv;
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 */
public long getCachePutSample() {
  long count = 0;
  for (String name : cacheManager.getCacheNames()) {
    Cache cache = cacheManager.getCache(name);
    if (cache != null) {
      count += cache.getStatistics().cachePutOperation().rate().value().longValue();
    }
  }
  return count;
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 */
public long getCacheMissSample() {
  long count = 0;
  for (String name : cacheManager.getCacheNames()) {
    Cache cache = cacheManager.getCache(name);
    if (cache != null) {
      count += cache.getStatistics().cacheMissOperation().rate().value().longValue();
    }
  }
  return count;
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 */
public long getCacheHitSample() {
  long count = 0;
  for (String name : cacheManager.getCacheNames()) {
    Cache cache = cacheManager.getCache(name);
    if (cache != null) {
      count += cache.getStatistics().cacheHitOperation().rate().value().longValue();
    }
  }
  return count;
}

相关文章

微信公众号

最新文章

更多

Cache类方法