@SuppressWarnings("rawtypes") public static List getKeys(String cacheName) { return getOrAddCache(cacheName).getKeys(); }
public static List getKeys(String cacheName) { return getOrAddCache(cacheName).getKeys(); }
public List<String> getCacheKeys(MerchantStore store) throws Exception { net.sf.ehcache.Cache cacheImpl = (net.sf.ehcache.Cache) cache.getNativeCache(); List<String> returnKeys = new ArrayList<String>(); for (Object key: cacheImpl.getKeys()) { try { String sKey = (String)key; // a key should be <storeId>_<rest of the key> int delimiterPosition = sKey.indexOf(KEY_DELIMITER); if(delimiterPosition>0 && Character.isDigit(sKey.charAt(0))) { String keyRemaining = sKey.substring(delimiterPosition+1); returnKeys.add(keyRemaining); } } catch (Exception e) { LOGGER.equals("key " + key + " cannot be converted to a String or parsed"); } } return returnKeys; }
public void removeAllFromCache(MerchantStore store) throws Exception { net.sf.ehcache.Cache cacheImpl = (net.sf.ehcache.Cache) cache.getNativeCache(); for (Object key: cacheImpl.getKeys()) { try { String sKey = (String)key; // a key should be <storeId>_<rest of the key> int delimiterPosition = sKey.indexOf(KEY_DELIMITER); if(delimiterPosition>0 && Character.isDigit(sKey.charAt(0))) { cache.evict(key); } } catch (Exception e) { LOGGER.equals("key " + key + " cannot be converted to a String or parsed"); } } }
private void clearCacheKey(String cacheId, String cacheKey) { final List<CacheManager> allCacheManagers = CacheManager.ALL_CACHE_MANAGERS; for (final CacheManager cacheManager : allCacheManagers) { final Cache cache = cacheManager.getCache(cacheId); if (cache != null) { final boolean removed = cache.remove(cacheKey); if (!removed) { // if keys are not Strings, we have to find the initial key for (final Object key : cache.getKeys()) { if (key != null && key.toString().equals(cacheKey)) { cache.remove(key); break; } } } } } }
public Collection keySet() { Cache cache = manager.getCache(ehcacheConf.getPredefinedCacheName()); return cache.getKeys(); }
/** * Returns a list of all elements in the cache, whether or not they are expired. * <p> * The returned keys are not unique and may contain duplicates. If the cache is only * using the memory store, the list will be unique. If the disk store is being used * as well, it will likely contain duplicates, because of the internal store design. * <p> * The List returned is not live. It is a copy. * <p> * The time taken is O(log n). On a single CPU 1.8Ghz P4, approximately 6ms is required * for 1000 entries and 36 for 50000. * <p> * This is the fastest getKeys method * * @return a list of {@link Object} keys * @throws IllegalStateException if the cache is not {@link Status#STATUS_ALIVE} */ public final List getKeysNoDuplicateCheck() throws IllegalStateException { checkStatus(); return getKeys(); }
/** * An extremely expensive check to see if the value exists in the cache. This implementation is O(n). Ehcache * is not designed for efficient access in this manner. * <p> * This method is not synchronized. It is possible that an element may exist in the cache and be removed * before the check gets to it, or vice versa. Because it is slow to execute the probability of that this will * have happened. * * @param value to check for * @return true if an Element matching the key is found in the cache. No assertions are made about the state of the Element. */ public boolean isValueInCache(Object value) { for (Object key : getKeys()) { Element element = get(key); if (element != null) { Object elementValue = element.getValue(); if (elementValue == null) { if (value == null) { return true; } } else { if (elementValue.equals(value)) { return true; } } } } return false; }
List allKeyList = getKeys();
@SuppressWarnings("unchecked") @Override public Collection<String> keys() { return cache.getKeys(); }
@SuppressWarnings("unchecked") public Collection<K> getKeys() { return cache.getKeys(); }
/** * {@inheritDoc } */ @Override public List<String> getKeys( ) { if ( _cache != null ) { return _cache.getKeys( ); } return new ArrayList<String>( ); }
public void showKeys() { List keys = cache.getKeys(); Collections.sort(keys); for (Object key : keys) { Element elem = cache.get(key); System.out.printf(" %40s == %s%n", key, elem); } }
@SuppressWarnings("unchecked") private List<?> getKeys(Cache ehcache, String keyword) { return (List<?>) ehcache.getKeys() .stream() .filter(o -> o instanceof String) .filter(o -> ((String) o).contains(keyword)) .collect(Collectors.toList()); }
/** {@inheritDoc} */ @Override public Set<String> listPropertyNames() { Set < String > propertyNames = new HashSet<String>(); for (Object key : wrapper.getCacheProperties().getKeys()) { propertyNames.add((String) key); } return propertyNames; }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public Set<String> listCachedPropertyNames() { return new HashSet<String>(getCacheProperties().getKeys()); }
/** {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public Set<String> listCachedFeatureNames() { return new HashSet<String>(getCacheFeatures().getKeys()); }
/** * Get the cache keys * * @param cacheName * @return cache keys */ private Collection keys(CACHE_NAME cacheName) { return cacheManager.getCache(cacheName.name()).getKeys(); }
@Override public List getKeys(String cacheName) { return getOrAddCache(cacheName).getKeys(); }
@Cacheable(value = "myCache", key = "") public List<UserInfo> getUsers() { Cache cache = ehCacheService.getCache("myCache"); System.out.println("cache.getKeys()="+cache.getKeys()); return userInfoDAO.query(new UserInfo()); }