@Override
    @SuppressWarnings("unchecked")
    public <T> T create(Class<T> extensionClass) {
        String extensionClassName = extensionClass.getName();
        ClassLoader extensionClassLoader = extensionClass.getClassLoader();

        if (!cache.containsKey(extensionClassLoader)) {
            cache.put(extensionClassLoader, new HashMap<>());
        }

        Map<String, Object> classLoaderBucket = cache.get(extensionClassLoader);

        if (classLoaderBucket.containsKey(extensionClassName)) {
            return (T) classLoaderBucket.get(extensionClassName);
        }

        T extension = super.create(extensionClass);
        if (extensionClassNames.isEmpty() || extensionClassNames.contains(extensionClassName)) {
            classLoaderBucket.put(extensionClassName, extension);
        }

        return extension;
    }
@Test
    @SuppressWarnings("unchecked")
    public void createNewEachTimeFromDifferentClassLoaders() throws Exception {
        ExtensionFactory extensionFactory = new SingletonExtensionFactory(pluginManager);

        // Get classpath locations
        URL[] classpathReferences = getClasspathReferences();

        // Create different classloaders for the classpath references and load classes respectively
        ClassLoader klassLoaderOne = new URLClassLoader(classpathReferences, null);
        Class klassOne = klassLoaderOne.loadClass(TestExtension.class.getName());
        ClassLoader klassLoaderTwo = new URLClassLoader(classpathReferences, null);
        Class klassTwo = klassLoaderTwo.loadClass(TestExtension.class.getName());

        // create instances
        Object instanceOne = extensionFactory.create(klassOne);
        Object instanceTwo = extensionFactory.create(klassTwo);

        // assert that instances not same
        assertNotSame(instanceOne, instanceTwo);
    }