javax.cache.Cache.forEach()方法的使用及代码示例

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

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

Cache.forEach介绍

暂无

代码示例

代码示例来源:origin: ehcache/ehcache3

@Test
public void foreach() {
 cache.put(1, "a");
 cache.put(2, "b");
 cache.put(3, "c");
 changesOf(0, 0, 3, 0);
 cache.forEach(e -> {});
 changesOf(3, 0, 0, 0);
}

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

/** {@inheritDoc} */
public Set<String> listCachedFeatureNames() {
  Set<String> keys = new HashSet<>();
  // Implements iterate, more elegant as stream how ?
  getFeaturesCache().forEach(e->keys.add(e.getKey()));
  return keys;
}

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

/** {@inheritDoc} */
@Override
public Set<String> listCachedPropertyNames() {
  Set<String> keys = new HashSet<>();
  // Implements iterate, more elegant as stream how ?
  getPropertiesCache().forEach(e->keys.add(e.getKey()));
  return keys;
}

代码示例来源:origin: hazelcast/hazelcast-code-samples

/**
   * Display the content of the "{@code timestable}" cache.
   */
  private void timesTables(CacheManager cacheManager) {
    log.info("-----------------------");

    Cache<Tuple, Integer> cache = cacheManager.getCache(TIMESTABLE_CACHE_NAME, Tuple.class, Integer.class);

    Map<Tuple, Integer> tmpMap = new TreeMap<>();
    cache.forEach(entry -> tmpMap.put(entry.getKey(), entry.getValue()));

    for (Map.Entry<Tuple, Integer> entry : tmpMap.entrySet()) {
      log.info(" => '{}' == '{}'", entry.getKey(), entry.getValue());
    }

    if (tmpMap.size() > 0) {
      log.info("-----------------------");
    }
    log.info("[{} cache entr{}]",
        tmpMap.size(),
        (tmpMap.size() == 1 ? "y" : "ies")
    );
    log.info("-----------------------");
  }
}

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

/** {@inheritDoc} */
@Override
public Set<String> listPropertyNames() {
  Set<String> setOfPropertyNames = new HashSet<>();
  getCacheManager().getPropertiesCache().forEach(e->setOfPropertyNames.add(e.getKey()));
  return setOfPropertyNames;
}

代码示例来源:origin: hazelcast/hazelcast-code-samples

/**
   * Dump the content of the 'timestable' cache.
   */
  @CliCommand(value = "timesTable", help = "Display the content of the 'timestable' cache")
  public void timestable() {
    log.info("-----------------------");

    Cache<Tuple, Integer> cache = this.cacheManager.getCache(TIMESTABLE_CACHE_NAME, Tuple.class, Integer.class);

    Map<Tuple, Integer> tmpMap = new TreeMap<>();
    cache.forEach(entry -> tmpMap.put(entry.getKey(), entry.getValue()));

    for (Map.Entry<Tuple, Integer> entry : tmpMap.entrySet()) {
      log.info(" => '{}' == '{}'", entry.getKey(), entry.getValue());
    }

    if (tmpMap.size() > 0) {
      log.info("-----------------------");
    }
    log.info("[{} cache entr{}]",
        tmpMap.size(),
        (tmpMap.size() == 1 ? "y" : "ies")
    );
    log.info("-----------------------");
  }
}

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

/** {@inheritDoc} */
@Override
public Map<String, Feature> readAll() {
  Map<String, Feature> myMap = new HashMap<>();
  getCacheManager().getFeaturesCache().forEach(e->myMap.put(e.getKey(), e.getValue()));
  return myMap;
}

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

/** {@inheritDoc} */
@Override
public Map<String, Property<?>> readAllProperties() {
  Map<String, Property<?>> myMap = new HashMap<>();
  getCacheManager().getPropertiesCache().forEach(e->myMap.put(e.getKey(), e.getValue()));
  return myMap;
}

代码示例来源:origin: org.sonatype.nexus/nexus-repository

@Override
protected void doStop() {
 historicDataCleaner.stop();
 if (cache != null) {
  log.debug("Saving asset download count cache to DB");
  /*
  All cache entries need to be saved before the DB stops.
  The listener's events are processed asynchronously, so they can't guarantee that.
  So, we manually save each entry and then call cache.clear()
  clear method removes all entries from the cache without notifying any listeners to avoid double counting
   */
  cache.forEach(entry -> cacheRemovalListener.accept(entry.getKey(), entry.getValue()));
  cache.clear();
  log.debug("Asset download counts saved successfully");
 }
 cache = null;
}

相关文章