| I agree that a cache shouldn't be created with the default configuration. Users are silently not using the caching configuration they think they are. I actually use the following class everywhere and it is included in JHipster.
public class NoDefaultJCacheRegionFactory extends JCacheRegionFactory {
public static final String EXCEPTION_MESSAGE = "All Hibernate caches should be created upfront. " +
"Please update CacheConfiguration.java to add";
@Override
protected Cache<Object, Object> createCache(String regionName, Properties properties, CacheDataDescription
metadata) {
throw new IllegalStateException(EXCEPTION_MESSAGE + " " + regionName);
}
}
So I would be happy to see it changed in hibernate-jcache. About serialization, it is indeed the default. This is from the JCache specification. I don't have the historical reason for that. I think it was to have the same behavior clustered or not. Out-of-the-box Ehcache does the opposite and everything is cached by reference. So when creating a cache, I will use an Ehcache configuration that I then bridge to a JCache one. Retrospectively, caching configurations are so different, they should never have been included in the JCache specification. They should have been left to the implementation. Like spring-cache does. Bottom line: Yes. The default configuration should not be allowed. It is *never* what the user want and he might never see it. |