class CacheUtils {

    public void evictSubset(CacheManager cacheManager, String cacheName, Predicate<CompositeKey> keyPredicate) {
        final Cache cache = cacheManager.getCache(cacheName);
        if (cache == null) throw new IllegalArgumentException("Unknown cache " + cacheName);
        final Object nativeCache = cache.getNativeCache();
        if (nativeCache instanceof net.sf.ehcache.Cache) {
            final net.sf.ehcache.Cache ehCache = (net.sf.ehcache.Cache) nativeCache;

            for (final Object key : ehCache.getKeys()) {
                if (key instanceof CompositeKey) {
                    // if entry is compositeKey and first param is different, skip it (be sure this is not to evict)
                    final CompositeKey compositeKey = ((CompositeKey) key);
                    if (!keyPredicate.test(compositeKey)) continue;
                }
                // if key is not composite key (unknown for evict) or has same serviceId, evict record
                ehCache.remove(key);
            }
        } else {
            // in case of using different cache manager, evict all records for sure
            cache.clear();
        }
    }

}