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

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

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

Ehcache.getKeys介绍

[英]Returns a list of all elements in the cache, whether or not they are expired.

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

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

The time taken is O(n). For large caches - or caches with high-latency storage this method can take a very long time to complete, may cause timeouts if using features such NonStopCache or transactions, and is not guaranteed to give a consistent view of the cache entry set. Usage is highly discouraged.
[中]返回缓存中所有元素的列表,无论它们是否过期。
返回的密钥是唯一的,可以视为一组。
返回的列表不是活动列表。这是一份副本。
所用时间为O(n)。对于大型缓存或具有高延迟存储的缓存,此方法可能需要很长时间才能完成,如果使用非操作缓存或事务等功能,可能会导致超时,并且不能保证提供缓存项集的一致视图。不鼓励使用。

代码示例

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

public List<String> getKeys() {
  return ehCache.getKeys();
}

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

public Set<K> keys() {
  try {
    @SuppressWarnings({"unchecked"})
    List<K> keys = cache.getKeys();
    if (!isEmpty(keys)) {
      return Collections.unmodifiableSet(new LinkedHashSet<K>(keys));
    } else {
      return Collections.emptySet();
    }
  } catch (Throwable t) {
    throw new CacheException(t);
  }
}

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

public Collection<V> values() {
  try {
    @SuppressWarnings({"unchecked"})
    List<K> keys = cache.getKeys();
    if (!isEmpty(keys)) {
      List<V> values = new ArrayList<V>(keys.size());
      for (K key : keys) {
        V value = get(key);
        if (value != null) {
          values.add(value);
        }
      }
      return Collections.unmodifiableList(values);
    } else {
      return Collections.emptyList();
    }
  } catch (Throwable t) {
    throw new CacheException(t);
  }
}

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

/**
 * {@inheritDoc}
 */
public List getKeys() throws IllegalStateException, CacheException {
  return underlyingCache.getKeys();
}

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

@SuppressWarnings("unchecked")
@Override
public Iterable<K> generateKeys(Ehcache cache) {
  return cache.getKeys();
}

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

/**
 * Returns a list of all elements in the cache, whether or not they are expired.
 * <p>
 * The returned keys are unique and can be considered a set.
 * <p>
 * The List returned is not live. It is a copy.
 * <p>
 * The time taken is O(n). On a single cpu 1.8Ghz P4, approximately 8ms is required
 * for each 1000 entries.
 *
 * @return a list of {@link Object} keys
 */
public List getKeys() throws RemoteException {
  List keys = cache.getKeys();
  if (keys instanceof Serializable) {
    return keys;
  }
  return new ArrayList(keys);
}

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

/**
* {@inheritDoc}
*/
public List getKeys() throws IllegalStateException, CacheException {
  // THIS IS GENERATED CODE -- DO NOT HAND MODIFY!
  Thread t = Thread.currentThread();
  ClassLoader prev = t.getContextClassLoader();
  t.setContextClassLoader(this.classLoader);
  try {
    return Collections.unmodifiableList(new ClassLoaderAwareList(this.cache.getKeys()));
  } finally {
    t.setContextClassLoader(prev);
  }
}

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

public void notifyRemoveAll(Ehcache ehcache) {
  // TODO Auto-generated method stub
  Iterator ite = ehcache.getKeys().iterator();
  while (ite.hasNext()) {
    Element e = ehcache.get(ite.next());
    try {
      Object model = e.getObjectValue();
      if (model instanceof LifeCycle) {
        LifeCycle lf = (LifeCycle) model;
        lf.stop();
      }
    } catch (Exception ex) {
    }
  }
}

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

/**
 * Performs bootstrap loading.  May be executed on a independent thread.
 */
protected void doLoad(Ehcache cache) {
  int loadedElements = 0;
  final Iterator iterator = cache.getKeys().iterator();
  while (iterator.hasNext() && !isInMemoryLimitReached(cache, loadedElements)) {
    if (cache.get(iterator.next()) != null) {
      ++loadedElements;
    }
  }
  LOG.debug("Loaded {} elements from disk into heap for cache {}", loadedElements, cache.getName());
}

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

/**
 * @return a copy of the cache Elements as a Map
 */
public final Map toMap() {
  try {
    Map result = new HashMap();
    for (Object key : cache.getKeys()) {
      Element e = cache.get(key);
      if (e != null) {
        result.put(key, e.getObjectValue());
      }
    }
    return result;
  } catch (Exception e) {
    throw new CacheException(e);
  }
}

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

this.cacheKeys = cache.getKeys();
} else {
  this.cacheKeys = null;

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

/**
 * {@inheritDoc}
 */
public Map toMap() {
  try {
    Map<Object, Object> result = new HashMap<Object, Object>();
    for (Object key : cache.getKeys()) {
      Element e = cache.get(key);
      if (e != null) {
        result.put(key, e.getObjectValue());
      }
    }
    return result;
  } catch (Exception e) {
    if (e instanceof NonStopCacheException) {
      HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e);
      return Collections.emptyMap();
    } else {
      throw new CacheException(e);
    }
  }
}

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

/**
 * {@inheritDoc}
 */
public List getKeys() throws IllegalStateException, CacheException {
  return underlyingCache.getKeys();
}

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

/**
 * Returns the keys for this cache.
 * 
 * @return a list of {@link Object} keys for this cache. This is not a live set, so it will not track changes to the key set.
 */
public List getKeys() throws CacheException {
  return cache.getKeys();
}

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

public List<String> getKeys() {
  ArrayList<String> keys = new ArrayList<String>();
  List<?> eKeys = cache.getKeys();
  for (Object object : eKeys) {
    if (object != null) {
      keys.add(object.toString());
    }
  }
  return keys;
}

代码示例来源:origin: org.dspace/dspace-services

public List<String> getKeys() {
  ArrayList<String> keys = new ArrayList<String>();
  List<?> eKeys = cache.getKeys();
  for (Object object : eKeys) {
    if (object != null) {
      keys.add(object.toString());
    }
  }
  return keys;
}

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

/**
 *
 * @return
 */
@Override
protected Collection keySet() {
  Ehcache cache = getOrCreateCache(cacheName);
  return cache.getKeys();
}

代码示例来源:origin: huangjian888/jeeweb-mybatis-springboot

@Override
public Set keys() {
  if (springCache.getNativeCache() instanceof Ehcache) {
    Ehcache ehcache = (Ehcache) springCache.getNativeCache();
    return new HashSet(ehcache.getKeys());
  }
  throw new UnsupportedOperationException("invoke spring cache abstract keys method not supported");
}

代码示例来源:origin: cn.jeeweb/jeeweb-common-security

@Override
public Set keys() {
  if (springCache.getNativeCache() instanceof Ehcache) {
    Ehcache ehcache = (Ehcache) springCache.getNativeCache();
    return new HashSet(ehcache.getKeys());
  }
  throw new UnsupportedOperationException("invoke spring cache abstract keys method not supported");
}

代码示例来源:origin: se.vgregion.commons-util/commons-util-core-bc-composite-svc-ldap

@Override
  public void run() {
    final List keys = cache.getKeys();
    for (Object key : keys) {
      final Element element1 = cache.get(key);
      if (element1 == null || element1.getObjectValue() == null
          || ((LdapUser) element1.getValue()).getDn() == null) {
        cache.remove(key);
      }
    }
  }
}, delay, TimeUnit.SECONDS);

相关文章

Ehcache类方法