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

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

本文整理了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

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

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

  1. public Set<K> keys() {
  2. try {
  3. @SuppressWarnings({"unchecked"})
  4. List<K> keys = cache.getKeys();
  5. if (!isEmpty(keys)) {
  6. return Collections.unmodifiableSet(new LinkedHashSet<K>(keys));
  7. } else {
  8. return Collections.emptySet();
  9. }
  10. } catch (Throwable t) {
  11. throw new CacheException(t);
  12. }
  13. }

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

  1. public Collection<V> values() {
  2. try {
  3. @SuppressWarnings({"unchecked"})
  4. List<K> keys = cache.getKeys();
  5. if (!isEmpty(keys)) {
  6. List<V> values = new ArrayList<V>(keys.size());
  7. for (K key : keys) {
  8. V value = get(key);
  9. if (value != null) {
  10. values.add(value);
  11. }
  12. }
  13. return Collections.unmodifiableList(values);
  14. } else {
  15. return Collections.emptyList();
  16. }
  17. } catch (Throwable t) {
  18. throw new CacheException(t);
  19. }
  20. }

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

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

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

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

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

  1. /**
  2. * Returns a list of all elements in the cache, whether or not they are expired.
  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). On a single cpu 1.8Ghz P4, approximately 8ms is required
  9. * for each 1000 entries.
  10. *
  11. * @return a list of {@link Object} keys
  12. */
  13. public List getKeys() throws RemoteException {
  14. List keys = cache.getKeys();
  15. if (keys instanceof Serializable) {
  16. return keys;
  17. }
  18. return new ArrayList(keys);
  19. }

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

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public List getKeys() 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 Collections.unmodifiableList(new ClassLoaderAwareList(this.cache.getKeys()));
  11. } finally {
  12. t.setContextClassLoader(prev);
  13. }
  14. }

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

  1. public void notifyRemoveAll(Ehcache ehcache) {
  2. // TODO Auto-generated method stub
  3. Iterator ite = ehcache.getKeys().iterator();
  4. while (ite.hasNext()) {
  5. Element e = ehcache.get(ite.next());
  6. try {
  7. Object model = e.getObjectValue();
  8. if (model instanceof LifeCycle) {
  9. LifeCycle lf = (LifeCycle) model;
  10. lf.stop();
  11. }
  12. } catch (Exception ex) {
  13. }
  14. }
  15. }

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

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

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

  1. /**
  2. * @return a copy of the cache Elements as a Map
  3. */
  4. public final Map toMap() {
  5. try {
  6. Map result = new HashMap();
  7. for (Object key : cache.getKeys()) {
  8. Element e = cache.get(key);
  9. if (e != null) {
  10. result.put(key, e.getObjectValue());
  11. }
  12. }
  13. return result;
  14. } catch (Exception e) {
  15. throw new CacheException(e);
  16. }
  17. }

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

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

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

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public Map toMap() {
  5. try {
  6. Map<Object, Object> result = new HashMap<Object, Object>();
  7. for (Object key : cache.getKeys()) {
  8. Element e = cache.get(key);
  9. if (e != null) {
  10. result.put(key, e.getObjectValue());
  11. }
  12. }
  13. return result;
  14. } catch (Exception e) {
  15. if (e instanceof NonStopCacheException) {
  16. HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e);
  17. return Collections.emptyMap();
  18. } else {
  19. throw new CacheException(e);
  20. }
  21. }
  22. }

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

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

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

  1. /**
  2. * Returns the keys for this cache.
  3. *
  4. * @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.
  5. */
  6. public List getKeys() throws CacheException {
  7. return cache.getKeys();
  8. }

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

  1. public List<String> getKeys() {
  2. ArrayList<String> keys = new ArrayList<String>();
  3. List<?> eKeys = cache.getKeys();
  4. for (Object object : eKeys) {
  5. if (object != null) {
  6. keys.add(object.toString());
  7. }
  8. }
  9. return keys;
  10. }

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

  1. public List<String> getKeys() {
  2. ArrayList<String> keys = new ArrayList<String>();
  3. List<?> eKeys = cache.getKeys();
  4. for (Object object : eKeys) {
  5. if (object != null) {
  6. keys.add(object.toString());
  7. }
  8. }
  9. return keys;
  10. }

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

  1. /**
  2. *
  3. * @return
  4. */
  5. @Override
  6. protected Collection keySet() {
  7. Ehcache cache = getOrCreateCache(cacheName);
  8. return cache.getKeys();
  9. }

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

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

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

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

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

  1. @Override
  2. public void run() {
  3. final List keys = cache.getKeys();
  4. for (Object key : keys) {
  5. final Element element1 = cache.get(key);
  6. if (element1 == null || element1.getObjectValue() == null
  7. || ((LdapUser) element1.getValue()).getDn() == null) {
  8. cache.remove(key);
  9. }
  10. }
  11. }
  12. }, delay, TimeUnit.SECONDS);

相关文章

Ehcache类方法