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

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

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

Ehcache.getKeysWithExpiryCheck介绍

[英]Returns a list of all elements in the cache. Only keys of non-expired elements are returned.

The returned keys are unique and can be considered a set.

The List returned is not live. It is a copy.

For large caches - or caches with high-latency storage this method can take a very long time to complete. You should seriously consider whether your usage requires checking for expired keys before choosing to call this method. As this method can take a long time the results may also be significantly out of date by the time the method returns.
[中]返回缓存中所有元素的列表。只返回未过期元素的键。
返回的密钥是唯一的,可以视为一组。
返回的列表不是活动列表。这是一份副本。
对于大型缓存或具有高延迟存储的缓存,此方法可能需要非常长的时间才能完成。在选择调用这个方法之前,您应该认真考虑您的使用是否需要检查过期的密钥。由于此方法可能需要很长时间,因此当该方法返回时,结果也可能明显过时。

代码示例

代码示例来源:origin: kaaproject/kaa

  1. @Override
  2. public List<SdkKey> getCachedSdkKeys(String applicationId) {
  3. List<SdkKey> keys = new ArrayList<>();
  4. Ehcache cache = (Ehcache) adminCacheManager.getCache(SDK_CACHE).getNativeCache();
  5. List<?> cachedKeys = cache.getKeysWithExpiryCheck();
  6. for (Object cachedKey : cachedKeys) {
  7. if (cachedKey instanceof SdkKey) {
  8. SdkKey cachedSdkKey = (SdkKey) cachedKey;
  9. if (applicationId.equals(cachedSdkKey.getSdkProfile().getApplicationId())) {
  10. keys.add(cachedSdkKey);
  11. }
  12. }
  13. }
  14. return keys;
  15. }

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

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public List getKeysWithExpiryCheck() throws IllegalStateException, CacheException {
  5. return underlyingCache.getKeysWithExpiryCheck();
  6. }

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

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public List getKeysWithExpiryCheck() throws IllegalStateException, CacheException {
  5. // THIS IS GENERATED CODE -- DO NOT HAND MODIFY!
  6. Thread t = Thread.currentThread();
  7. ClassLoader prev = t.getContextClassLoader();
  8. t.setContextClassLoader(this.classLoader);
  9. try {
  10. return this.cache.getKeysWithExpiryCheck();
  11. } finally {
  12. t.setContextClassLoader(prev);
  13. }
  14. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.ehcache

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public List getKeysWithExpiryCheck() throws IllegalStateException, CacheException {
  5. return underlyingCache.getKeysWithExpiryCheck();
  6. }

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

  1. @SuppressWarnings("unchecked")
  2. public Collection<String> getTokenIdentifiers() {
  3. if (cache == null) {
  4. return null;
  5. }
  6. return cache.getKeysWithExpiryCheck();
  7. }

代码示例来源:origin: org.apache.cxf/cxf-rt-ws-security

  1. @SuppressWarnings("unchecked")
  2. public Collection<String> getTokenIdentifiers() {
  3. if (cache == null) {
  4. return null;
  5. }
  6. return cache.getKeysWithExpiryCheck();
  7. }

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

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public List getKeysWithExpiryCheck() throws IllegalStateException, CacheException {
  5. return underlyingCache.getKeysWithExpiryCheck();
  6. }

代码示例来源:origin: org.sonatype.nexus.bundles/org.sonatype.nexus.bundles.ehcache

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public List getKeysWithExpiryCheck() throws IllegalStateException, CacheException {
  5. return underlyingCache.getKeysWithExpiryCheck();
  6. }

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

  1. /**
  2. * Returns a list of all elements in the cache. Only keys of non-expired elements are returned.
  3. * <p/>
  4. * The returned keys are unique and can be considered a set.
  5. * <p/>
  6. * The List returned is not live. It is a copy.
  7. * <p/>
  8. * The time taken is O(n), where n is the number of elements in the cache. On a 1.8Ghz P4, the time taken is approximately 200ms per
  9. * 1000 entries. This method is not synchronized, because it relies on a non-live list returned from {@link #getKeys()} , which is
  10. * synchronised, and which takes 8ms per 1000 entries. This way cache liveness is preserved, even if this method is very slow to return.
  11. * <p/>
  12. * Consider whether your usage requires checking for expired keys. Because this method takes so long, depending on cache settings, the
  13. * list could be quite out of date by the time you get it.
  14. *
  15. * @return a list of {@link Object} keys
  16. * @throws IllegalStateException
  17. * if the cache is not {@link net.sf.ehcache.Status#STATUS_ALIVE}
  18. */
  19. public List getKeysWithExpiryCheck() throws IllegalStateException, CacheException {
  20. return cache.getKeysWithExpiryCheck();
  21. }

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

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public List getKeysWithExpiryCheck() throws IllegalStateException, CacheException {
  5. // THIS IS GENERATED CODE -- DO NOT HAND MODIFY!
  6. Thread t = Thread.currentThread();
  7. ClassLoader prev = t.getContextClassLoader();
  8. t.setContextClassLoader(this.classLoader);
  9. try {
  10. return this.cache.getKeysWithExpiryCheck();
  11. } finally {
  12. t.setContextClassLoader(prev);
  13. }
  14. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.ehcache

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public List getKeysWithExpiryCheck() throws IllegalStateException, CacheException {
  5. // THIS IS GENERATED CODE -- DO NOT HAND MODIFY!
  6. Thread t = Thread.currentThread();
  7. ClassLoader prev = t.getContextClassLoader();
  8. t.setContextClassLoader(this.classLoader);
  9. try {
  10. return this.cache.getKeysWithExpiryCheck();
  11. } finally {
  12. t.setContextClassLoader(prev);
  13. }
  14. }

代码示例来源:origin: org.sonatype.nexus.bundles/org.sonatype.nexus.bundles.ehcache

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public List getKeysWithExpiryCheck() throws IllegalStateException, CacheException {
  5. // THIS IS GENERATED CODE -- DO NOT HAND MODIFY!
  6. Thread t = Thread.currentThread();
  7. ClassLoader prev = t.getContextClassLoader();
  8. t.setContextClassLoader(this.classLoader);
  9. try {
  10. return this.cache.getKeysWithExpiryCheck();
  11. } finally {
  12. t.setContextClassLoader(prev);
  13. }
  14. }

代码示例来源:origin: rtyley/mini-git-server

  1. @SuppressWarnings("unchecked")
  2. public List getKeysWithExpiryCheck() throws IllegalStateException,
  3. CacheException {
  4. return self().getKeysWithExpiryCheck();
  5. }

代码示例来源:origin: org.apereo.cas/cas-server-support-ehcache-ticket-registry

  1. private static Map<Object, Element> getAllExpired(final Ehcache map) {
  2. try {
  3. return map.getAll(map.getKeysWithExpiryCheck());
  4. } catch (final Exception e) {
  5. LOGGER.warn(e.getMessage(), e);
  6. return new HashMap<>(0);
  7. }
  8. }
  9. }

代码示例来源:origin: com.madgag/mini-git-server-server

  1. @SuppressWarnings("unchecked")
  2. public List getKeysWithExpiryCheck() throws IllegalStateException,
  3. CacheException {
  4. return self().getKeysWithExpiryCheck();
  5. }

代码示例来源:origin: org.sakaiproject.kernel/sakai-kernel-impl

  1. void logCacheState(String operator) {
  2. if (cacheDebug) {
  3. String name = m_callCache.getName();
  4. net.sf.ehcache.Ehcache ehcache = m_callCache.unwrap(Ehcache.class); // DEBUGGING ONLY
  5. StringBuilder entriesSB = new StringBuilder();
  6. List keys = ehcache.getKeysWithExpiryCheck(); // only current keys
  7. entriesSB.append(" * keys(").append(keys.size()).append("):").append(new ArrayList<Object>(keys)).append("\n");
  8. Collection<Element> entries = ehcache.getAll(keys).values();
  9. int countMaps = 0;
  10. for (Element element : entries) {
  11. if (element == null) continue;
  12. int count = 0;
  13. countMaps += count;
  14. if (cacheDebugDetailed) {
  15. entriesSB.append(" ").append(element.getObjectKey()).append(" => (").append(count).append(")").append(element.getObjectValue()).append("\n");
  16. }
  17. }
  18. log.info("SScache:"+name+":: "+operator+" ::\n entries(Ehcache[key => payload],"+keys.size()+" + "+countMaps+" = "+(keys.size()+countMaps)+"):\n"+entriesSB);
  19. }
  20. }

代码示例来源:origin: org.terracotta/ehcache-probe

  1. @RestMethod(required = { PARAM_CACHE, PARAM_COUNT }, optional = { PARAM_QUERY })
  2. public void getCacheKeys(RestRequest request, RestResponse response)
  3. throws IOException {
  4. String cacheName = request.getParameter(PARAM_CACHE);
  5. String countString = request.getParameter(PARAM_COUNT);
  6. String query = request.getParameter(PARAM_QUERY);
  7. int count = Integer.parseInt(countString);
  8. if (count <= 0) {
  9. throw new IllegalArgumentException("count needs to be positive");
  10. }
  11. Ehcache cache = cacheManager.getEhcache(cacheName);
  12. response.childType(ELEMENT_KEY);
  13. if (cache != null) {
  14. List keys = cache.getKeysWithExpiryCheck();
  15. Iterator it = keys.iterator();
  16. while (count > 0 && it.hasNext()) {
  17. Object key = it.next();
  18. if (null == query || queryKey(key, query)) {
  19. count--;
  20. response.child(key);
  21. }
  22. }
  23. }
  24. }

代码示例来源:origin: org.terracotta/ehcache-probe

  1. @RestMethod(required = { PARAM_CACHE, PARAM_QUERY })
  2. public void removeQueryFromCache(RestRequest request, RestResponse response)
  3. throws IOException {
  4. String cacheName = request.getParameter(PARAM_CACHE);
  5. String query = request.getParameter(PARAM_QUERY);
  6. int count = 0;
  7. Ehcache cache = cacheManager.getEhcache(cacheName);
  8. if (cache != null) {
  9. List<Object> keys = cache.getKeysWithExpiryCheck();
  10. for (Object key : keys) {
  11. if (queryKey(key, query)) {
  12. if (cache.removeQuiet(key)) {
  13. count++;
  14. }
  15. }
  16. }
  17. response.value(count);
  18. }
  19. }

相关文章

Ehcache类方法