use of net.sf.ehcache.CacheManager in project hibernate-orm by hibernate.
the class EhCacheRegionFactory method start.
@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
this.settings = settings;
if (manager != null) {
LOG.attemptToRestartAlreadyStartedEhCacheProvider();
return;
}
try {
String configurationResourceName = null;
if (properties != null) {
configurationResourceName = (String) properties.get(NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME);
}
if (configurationResourceName == null || configurationResourceName.length() == 0) {
final Configuration configuration = ConfigurationFactory.parseConfiguration();
manager = new CacheManager(configuration);
} else {
final URL url = loadResource(configurationResourceName);
final Configuration configuration = HibernateEhcacheUtils.loadAndCorrectConfiguration(url);
manager = new CacheManager(configuration);
}
mbeanRegistrationHelper.registerMBean(manager, properties);
} catch (net.sf.ehcache.CacheException e) {
if (e.getMessage().startsWith("Cannot parseConfiguration CacheManager. Attempt to create a new instance of " + "CacheManager using the diskStorePath")) {
throw new CacheException("Attempt to restart an already started EhCacheRegionFactory. " + "Use sessionFactory.close() between repeated calls to buildSessionFactory. " + "Consider using SingletonEhCacheRegionFactory. Error from ehcache was: " + e.getMessage());
} else {
throw new CacheException(e);
}
}
}
use of net.sf.ehcache.CacheManager in project CloudStack-archive by CloudStack-extras.
the class GenericDaoBase method createCache.
@DB(txn = false)
protected void createCache(final Map<String, ? extends Object> params) {
final String value = (String) params.get("cache.size");
if (value != null) {
final CacheManager cm = CacheManager.create();
final int maxElements = NumbersUtil.parseInt(value, 0);
final int live = NumbersUtil.parseInt((String) params.get("cache.time.to.live"), 300);
final int idle = NumbersUtil.parseInt((String) params.get("cache.time.to.idle"), 300);
_cache = new Cache(getName(), maxElements, false, live == -1, live == -1 ? Integer.MAX_VALUE : live, idle);
cm.addCache(_cache);
s_logger.info("Cache created: " + _cache.toString());
} else {
_cache = null;
}
}
use of net.sf.ehcache.CacheManager in project cloudstack by apache.
the class IAMServiceImpl method createIAMCache.
private void createIAMCache(final Map<String, ? extends Object> params) {
final String value = (String) params.get("cache.size");
if (value != null) {
final CacheManager cm = CacheManager.create();
final int maxElements = NumbersUtil.parseInt(value, 0);
final int live = NumbersUtil.parseInt((String) params.get("cache.time.to.live"), 300);
final int idle = NumbersUtil.parseInt((String) params.get("cache.time.to.idle"), 300);
_iamCache = new Cache(getName(), maxElements, false, live == -1, live == -1 ? Integer.MAX_VALUE : live, idle);
cm.addCache(_iamCache);
s_logger.info("IAM Cache created: " + _iamCache.toString());
} else {
_iamCache = null;
}
}
use of net.sf.ehcache.CacheManager in project spring-framework by spring-projects.
the class EhCacheManagerUtils method buildCacheManager.
/**
* Build an EhCache {@link CacheManager} from the given configuration resource.
* @param name the desired name of the cache manager
* @param configLocation the location of the configuration file (as a Spring resource)
* @return the new EhCache CacheManager
* @throws CacheException in case of configuration parsing failure
*/
public static CacheManager buildCacheManager(String name, Resource configLocation) throws CacheException {
Configuration configuration = parseConfiguration(configLocation);
configuration.setName(name);
return new CacheManager(configuration);
}
use of net.sf.ehcache.CacheManager in project killbill by killbill.
the class EhCacheCacheManagerProvider method get.
@Override
public CacheManager get() {
final CacheManager cacheManager;
try {
final InputStream inputStream = UriAccessor.accessUri(cacheConfig.getCacheConfigLocation());
cacheManager = CacheManager.create(inputStream);
} catch (final IOException e) {
throw new RuntimeException(e);
} catch (final URISyntaxException e) {
throw new RuntimeException(e);
}
for (final BaseCacheLoader cacheLoader : cacheLoaders) {
cacheLoader.init();
final Ehcache cache = cacheManager.getEhcache(cacheLoader.getCacheType().getCacheName());
if (cache == null) {
logger.warn("Cache for cacheName='{}' not configured - check your ehcache.xml", cacheLoader.getCacheType().getCacheName());
continue;
}
// Make sure we start from a clean state - this is mainly useful for tests
for (final CacheLoader existingCacheLoader : cache.getRegisteredCacheLoaders()) {
cache.unregisterCacheLoader(existingCacheLoader);
}
cache.registerCacheLoader(cacheLoader);
// Instrument the cache
final Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry, cache);
try {
cacheManager.replaceCacheWithDecoratedCache(cache, decoratedCache);
} catch (final CacheException e) {
logger.warn("Unable to instrument cache {}: {}", cache.getName(), e.getMessage());
}
}
return cacheManager;
}
Aggregations