/** * Gets the secondary keys that are registered with the class in CacheMap. * * @param clazz the class * @param a the array to receive the keys. * @return the secondary keys. */ public K[] getKeys(Class<?> clazz, K[] a) { Cache<K, T> cache = getCache(clazz); if (cache != null) { Set<K> set = cache.keySet(); return set.toArray(a); } else { return a; } }
/** * Remove all registrations for the designated class. * * @param clazz the class */ @SuppressWarnings("unchecked") public void remove(Class<?> clazz) { Cache<K, T> cache = getCache(clazz); if (cache != null) { Object[] keys = cache.keySet().toArray(); for (Object context : keys) { cache.setObject((K) context, null); } } _cache.remove(clazz); }
/** * 清除缓存中该dataKey的相关所有缓存数据 当该dataKey相关的数据增删改时,调用本方法。以便及时清除缓存。 * * <p>dataKey是数据的ID,如ProductId , ItemId等 * * @param dataKey * @param formName */ public void removeCache(Object dataKey) { if (dataKey == null) return; try { for (Object o : cache.keySet()) { String key = (String) o; Object cachedValue = (Object) cache.get(key); if (cachedValue instanceof CacheableWrapper) { CacheableWrapper cw = (CacheableWrapper) cachedValue; if (cw.getCachedValueKey().equals(dataKey.toString())) removeObect(key); } } } catch (Exception e) { e.printStackTrace(); } }
/** * {@inheritDoc} * * @see java.util.Map#keySet() */ public Set keySet() { _log.debug(getType() + ".keySet() [" + getName() + "]"); return _cache.keySet(); }