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

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

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

Cache.getSize介绍

[英]Gets the size of the cache. This is a subtle concept. See below.

This number is the actual number of elements, including expired elements that have not been removed.

Expired elements are removed from the the memory store when getting an expired element, or when attempting to spool an expired element to disk.

Expired elements are removed from the disk store when getting an expired element, or when the expiry thread runs, which is once every five minutes.

To get an exact size, which would exclude expired elements, use #getKeysWithExpiryCheck().size(), although see that method for the approximate time that would take.

To get a very fast result, use #getKeysNoDuplicateCheck().size(). If the disk store is being used, there will be some duplicates.

Note:getSize() is a very expensive operation in off-heap, disk and Terracotta implementations.
[中]获取缓存的大小。这是一个微妙的概念。见下文。
此数字是元素的实际数量,包括尚未删除的过期元素。
获取过期元素或尝试将过期元素假脱机到磁盘时,将从内存存储中删除过期元素。
获取过期元素时,或当过期线程运行时(每五分钟一次),会从磁盘存储中删除过期元素。
要获得排除过期元素的确切大小,请使用#getKeysWithExpiryCheck()。size(),但请参阅该方法以了解所需的大致时间。
要获得非常快速的结果,请使用#GetKeysNodeUpplicateCheck()。大小()。如果正在使用磁盘存储,则会有一些重复项。
注意:getSize()在堆外、磁盘和Terracotta实现中是一个非常昂贵的操作。

代码示例

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

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("1") == null);
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("2") == null);
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: Impetus/Kundera

@Override
public int size()
{
  if(isAlive())
  {
    return ehcache.getSize();
  }
  return 0;
}

代码示例来源:origin: lutece-platform/lutece-core

/**
 * {@inheritDoc }
 */
@Override
public int getCacheSize( )
{
  return _cache.getSize( );
}

代码示例来源:origin: lutece-platform/lutece-core

/**
 * Gets the number of item currently in the cache.
 *
 * @return the number of item currently in the cache.
 */
@Override
public int getCacheSize( )
{
  return ( _cache != null ) ? _cache.getSize( ) : 0;
}

代码示例来源:origin: org.apache.marmotta/kiwi-caching-ehcache

@Override
public int size() {
  return delegate.getSize();
}

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

@Override
public int size() {
  return delegate.getSize();
}

代码示例来源:origin: org.jasig.cas/cas-server-extension-clearpass

@Override
public boolean isEmpty() {
  return this.cache.getSize() == 0;
}

代码示例来源:origin: org.apache.marmotta/kiwi-caching-ehcache

@Override
public boolean isEmpty() {
  return delegate.getSize() == 0;
}

代码示例来源:origin: com.ning.billing/killbill-util

@Override
public int size() {
  return cache.getSize();
}

代码示例来源:origin: org.jasig.cas/cas-server-extension-clearpass

@Override
public int size() {
  return this.cache.getSize();
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-sql

@Override
  public Integer getValue() {
    if (cacheManager != null) {
      return cacheManager.getCache(CACHE_NAME).getSize();
    }
    return 0;
  }
});

代码示例来源:origin: org.openxri/openxri-client

/**
 * get the number of cached elements currently cached
 * @return
 */
public int getSize()
{
  Cache cache = cacheManager.getCache(cacheName);
  return cache.getSize();
}

代码示例来源:origin: com.intuit.wasabi/wasabi-assignment

/**
 * @return Get metadata cache details
 */
@Override
public Map<String, String> getDetails() {
  Map<String, String> details = new HashMap<>();
  details.put("status", "Enabled");
  for (CACHE_NAME name : CACHE_NAME.values()) {
    details.put(name + ".SIZE", String.valueOf(cacheManager.getCache(name.toString()).getSize()));
  }
  return details;
}

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

public long getElementCountInMemory() {
  try {
    return cache.getSize();
  }
  catch (net.sf.ehcache.CacheException ce) {
    throw new CacheException(ce);
  }
}

代码示例来源:origin: org.craftercms/crafter-core

/**
 * {@inheritDoc}
 */
@Override
public int getSize(String scope) throws Exception {
  return getScopeCache(scope).getSize();
}

代码示例来源:origin: org.apache.cayenne/cayenne-server

public int size() {
  int size = 0;
  for (String cache : cacheManager.getCacheNames()) {
    size += cacheManager.getCache(cache).getSize();
  }
  return size;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-sql

protected int ehCacheGetSize() {
  if (useEhCache()) {
    return cache.getSize();
  }
  return 0;
}

代码示例来源:origin: bonitasoft/bonita-engine

@Override
public int getCacheSize(final String cacheName) throws SCacheException {
  if (cacheManager == null) {
    return 0;
  }
  final Cache cache = cacheManager.getCache(getKeyFromCacheName(cacheName));
  if (cache == null) {
    return 0;
  }
  return cache.getSize();
}

代码示例来源:origin: bonitasoft/bonita-engine

@Override
public int getCacheSize(final String cacheName) throws SCacheException {
  if (cacheManager == null) {
    return 0;
  }
  final Cache cache = cacheManager.getCache(getKeyFromCacheName(cacheName));
  if (cache == null) {
    return 0;
  }
  return cache.getSize();
}

代码示例来源:origin: edu.ucar/netcdf

public void stats() {
 System.out.printf(" elems added= %s%n", addElements.get());
 System.out.printf(" reqs= %d%n", requests.get());
 System.out.printf(" hits= %d%n", hits.get());
 if (cache != null) {
  System.out.printf(" cache= %s%n", cache.toString());
  System.out.printf(" cache.size= %d%n", cache.getSize());
  System.out.printf(" cache.memorySize= %d%n", cache.getMemoryStoreSize());
  Statistics stats = cache.getStatistics();
  System.out.printf(" stats= %s%n", stats.toString());
 }
}

相关文章

Cache类方法