Skip to content

Commit

Permalink
HHH-13090 Allow to use specific cache implementations in Ehcache cach…
Browse files Browse the repository at this point in the history
…e provider

Typically, it allows to use a BlockingCache.
  • Loading branch information
Mykola Pavluchynskyi authored and gsmet committed Nov 8, 2018
1 parent c17e483 commit 736d9dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Expand Up @@ -11,7 +11,7 @@
import java.util.List;
import java.util.Map;

import net.sf.ehcache.Cache;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.config.Configuration;
import net.sf.ehcache.config.ConfigurationFactory;
Expand Down Expand Up @@ -131,7 +131,7 @@ protected final String defaultRegionName(String regionName, SessionFactoryImplem
return regionName;
}

protected Cache getOrCreateCache(String unqualifiedRegionName, SessionFactoryImplementor sessionFactory) {
protected Ehcache getOrCreateCache(String unqualifiedRegionName, SessionFactoryImplementor sessionFactory) {
verifyStarted();
assert !RegionNameQualifier.INSTANCE.isQualified( unqualifiedRegionName, sessionFactory.getSessionFactoryOptions() );

Expand All @@ -140,25 +140,25 @@ protected Cache getOrCreateCache(String unqualifiedRegionName, SessionFactoryImp
sessionFactory.getSessionFactoryOptions()
);

final Cache cache = cacheManager.getCache( qualifiedRegionName );
final Ehcache cache = cacheManager.getEhcache( qualifiedRegionName );
if ( cache == null ) {
return createCache( qualifiedRegionName );
}
return cache;
}

protected Cache createCache(String regionName) {
protected Ehcache createCache(String regionName) {
switch ( missingCacheStrategy ) {
case CREATE_WARN:
SecondLevelCacheLogger.INSTANCE.missingCacheCreated(
regionName,
ConfigSettings.MISSING_CACHE_STRATEGY, MissingCacheStrategy.CREATE.getExternalRepresentation()
);
cacheManager.addCache( regionName );
return cacheManager.getCache( regionName );
return cacheManager.getEhcache( regionName );
case CREATE:
cacheManager.addCache( regionName );
return cacheManager.getCache( regionName );
return cacheManager.getEhcache( regionName );
case FAIL:
throw new CacheException( "On-the-fly creation of Ehcache Cache objects is not supported [" + regionName + "]" );
default:
Expand All @@ -171,13 +171,14 @@ protected boolean cacheExists(String unqualifiedRegionName, SessionFactoryImplem
unqualifiedRegionName,
sessionFactory.getSessionFactoryOptions()
);
return cacheManager.getCache( qualifiedRegionName ) != null;
return cacheManager.getEhcache( qualifiedRegionName ) != null;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Lifecycle

@Override
protected boolean isStarted() {
return super.isStarted() && cacheManager != null;
}
Expand Down
Expand Up @@ -6,7 +6,7 @@
*/
package org.hibernate.cache.ehcache.internal;

import net.sf.ehcache.Cache;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import net.sf.ehcache.constructs.nonstop.NonStopCacheException;
import net.sf.ehcache.hibernate.nonstop.HibernateNonstopCacheExceptionHandler;
Expand All @@ -25,14 +25,14 @@
public class StorageAccessImpl implements DomainDataStorageAccess {
private static final Logger LOG = Logger.getLogger( StorageAccessImpl.class );

private final Cache cache;
private final Ehcache cache;

@SuppressWarnings("WeakerAccess")
public StorageAccessImpl(Cache cache) {
public StorageAccessImpl(Ehcache cache) {
this.cache = cache;
}

public Cache getCache() {
public Ehcache getCache() {
return cache;
}

Expand Down

0 comments on commit 736d9dd

Please sign in to comment.