CustomJCacheRegionFactory.java

/*
 * Copyright 2026 Global Crop Diversity Trust
 * Licensed under the Apache License, Version 2.0
 * See LICENSE file in project root folder or http://www.apache.org/licenses/LICENSE-2.0
 */

package org.gringlobal.custom.cache;

import javax.cache.Cache;
import javax.cache.configuration.MutableConfiguration;

import org.ehcache.config.CacheConfiguration;
import org.ehcache.jsr107.Eh107Configuration;
import org.hibernate.cache.jcache.internal.JCacheRegionFactory;

public class CustomJCacheRegionFactory extends JCacheRegionFactory {
	private static final long serialVersionUID = 526279678137175597L;

	public static CacheConfiguration<Object, Object> cacheConfig;

	@Override
	protected Cache<Object, Object> createCache(String regionName) {
		var cacheManager = getCacheManager();
		if (cacheConfig != null) {
			return cacheManager.createCache(regionName, Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfig));
		} else {
			return cacheManager.createCache(regionName, new MutableConfiguration<>());
		}
	}

}