class CacheUtils {

    public <T> List<T> getAllRecords(CacheManager cacheManager, String cacheName) {
        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;

            return (List<T>) ehCache.getAll(ehCache.getKeys())
                .values()
                .stream()
                .map(Element::getObjectValue)
                .collect(Collectors.toList());
        } else {
            throw new IllegalArgumentException("Unsupported type of cache : " + nativeCache.getClass());
        }
    }

}