Java Code Examples for net.sf.ehcache.Ehcache#getKeys()

The following examples show how to use net.sf.ehcache.Ehcache#getKeys() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CmsSiteFlowMngImpl.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public int freshCacheToDB(Ehcache cache) {
	int count = 0;
	List<String> list = cache.getKeys();
	for (String uuid : list) {
		Element element = cache.get(uuid);
		if (element == null) {
			return count;
		}
		CmsSiteFlow cmsSiteFlow = (CmsSiteFlow) element.getValue();
		if (cmsSiteFlow.getId() == null
				&& cmsSiteFlow.getSessionId() != null) {
			dao.save(cmsSiteFlow);
		}
	}
	return count;
}
 
Example 2
Source File: ApplicationCache.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public void run() {
	out: while (true) {
		try {
			WrapClearCacheRequest wi = ReceiveQueue.take();
			if (wi instanceof StopReceiveThreadSignal) {
				break out;
			}
			for (String str : INSTANCE.manager.getCacheNames()) {
				/** 缓存名可能由多组组成 */
				if (ArrayUtils.contains(StringUtils.split(str, SPLIT), wi.getClassName())) {
					Ehcache cache = INSTANCE.getCache(str);
					List<Object> keys = wi.getKeys();
					if (ListTools.isNotEmpty(keys)) {
						/** 根据给定的关键字进行删除 */
						List<Object> removes = new ArrayList<>();
						for (Object key : keys) {
							for (Object o : cache.getKeys()) {
								if (Objects.equals(o, key)) {
									removes.add(o);
								}
								if (StringUtils.startsWith(o.toString(), key + SPLIT)) {
									removes.add(o);
								}
							}
						}
						if (!removes.isEmpty()) {
							cache.removeAll(removes);
						}
					} else {
						cache.removeAll();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	System.out.println("ApplicationCache ReceiveThread stoped!");
}
 
Example 3
Source File: CacheManagerWrapper.java    From cms with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example 4
Source File: SpringCacheManagerWrapper.java    From PhrackCTF-Platform-Team with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
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");
      }
 
Example 5
Source File: SpringCacheManagerWrapper.java    From roncoo-pay with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@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");
}
 
Example 6
Source File: SpringCacheManagerWrapper.java    From PhrackCTF-Platform-Personal with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
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");
      }
 
Example 7
Source File: MultiMarkupEhCacheProvider.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public Collection<T> getValues() {
    final Ehcache ehcache = (Ehcache) CACHE.getNativeCache();
    final List<T> values = new ArrayList<>();
    for (final Object key : ehcache.getKeys()) {
        final Element elem = ehcache.get(key);
        if (elem.getObjectValue() != null && !elem.isExpired()) {
           final T val = (T) elem.getObjectValue();
            values.add(val);
        }
    }
    return values;
}
 
Example 8
Source File: ContentCountDaoImpl.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public int freshCacheToDB(Ehcache cache) {
	List<Integer> keys = cache.getKeys();
	if (keys.size() <= 0) {
		return 0;
	}
	Element e;
	Integer views;
	int i = 0;
	String hql = "update ContentCount bean"
			+ " set bean.views=bean.views+:views"
			+ ",bean.viewsMonth=bean.viewsMonth+:views"
			+ ",bean.viewsWeek=bean.viewsWeek+:views"
			+ ",bean.viewsDay=bean.viewsDay+:views" + " where bean.id=:id";
	Query query = getSession().createQuery(hql);
	for (Integer id : keys) {
		e = cache.get(id);
		if (e != null) {
			views = (Integer) e.getValue();
			if (views != null) {
				query.setParameter("views", views);
				query.setParameter("id", id);
				i += query.executeUpdate();
			}
		}
	}
	return i;
}
 
Example 9
Source File: MultiMarkupEhCacheProvider.java    From yes-cart with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public Collection<String> getKeys() {
    final Ehcache ehcache = (Ehcache) CACHE.getNativeCache();
    return ehcache.getKeys();
}