class CacheKey implements Key {

        private final List<? extends ClassRealm> extensionRealms;

        private final int hashCode;

        public CacheKey(List<? extends ClassRealm> extensionRealms) {
            this.extensionRealms =
                    (extensionRealms != null) ? Collections.unmodifiableList(extensionRealms) : Collections.emptyList();

            this.hashCode = this.extensionRealms.hashCode();
        }

        @Override
        public int hashCode() {
            return hashCode;
        }

        @Override
        public boolean equals(Object o) {
            if (o == this) {
                return true;
            }

            if (!(o instanceof CacheKey)) {
                return false;
            }

            CacheKey other = (CacheKey) o;

            return extensionRealms.equals(other.extensionRealms);
        }

        @Override
        public String toString() {
            return extensionRealms.toString();
        }
    }

    protected final Map<Key, CacheRecord> cache = new ConcurrentHashMap<>();

    @Override
    public Key createKey(List<? extends ClassRealm> extensionRealms) {
        return new CacheKey(extensionRealms);
    }

    public CacheRecord get(Key key) {
        return cache.get(key);
    }

    public CacheRecord put(Key key, ClassRealm projectRealm, DependencyFilter extensionArtifactFilter) {
        Objects.requireNonNull(projectRealm, "projectRealm cannot be null");

        if (cache.containsKey(key)) {
            throw new IllegalStateException("Duplicate project realm for extensions " + key);
        }

        CacheRecord record = new CacheRecord(projectRealm, extensionArtifactFilter);

        cache.put(key, record);

        return record;
    }

    public void flush() {<FILL_FUNCTION_BODY>

        for (CacheRecord record : cache.values()) {
            ClassRealm realm = record.getRealm();
            try {
                realm.getWorld().disposeRealm(realm.getId());
            } catch (NoSuchRealmException e) {
                // ignore
            }
        }
        cache.clear();
    
<no_super_class>