net.sf.ehcache.config.ConfigurationFactory Java Examples

The following examples show how to use net.sf.ehcache.config.ConfigurationFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebEhCacheManagerFacotryBean.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
public void afterPropertiesSet() throws IOException, CacheException {
	log.info("Initializing EHCache CacheManager");
	Configuration config = null;
	if (this.configLocation != null) {
		config = ConfigurationFactory
				.parseConfiguration(this.configLocation.getInputStream());
		if (this.diskStoreLocation != null) {
			DiskStoreConfiguration dc = new DiskStoreConfiguration();
			dc.setPath(this.diskStoreLocation.getFile().getAbsolutePath());
			try {
				config.addDiskStore(dc);
			} catch (ObjectExistsException e) {
				log.warn("if you want to config distStore in spring,"
						+ " please remove diskStore in config file!", e);
			}
		}
	}
	if (config != null) {
		this.cacheManager = new CacheManager(config);
	} else {
		this.cacheManager = new CacheManager();
	}
	if (this.cacheManagerName != null) {
		this.cacheManager.setName(this.cacheManagerName);
	}
}
 
Example #2
Source File: EhcacheManager.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void init() {

        Configuration config = ConfigurationFactory.parseConfiguration();
        config.setClassLoader(ehcacheClassloader);

        String maxBytesLocalHeap = JbootConfigManager.me().getConfigValue("jpress.ehcache.maxBytesLocalHeap");
        config.setMaxBytesLocalHeap(StrUtil.obtainDefaultIfBlank(maxBytesLocalHeap, "100M"));

        String maxBytesLocalDisk = JbootConfigManager.me().getConfigValue("jpress.ehcache.maxBytesLocalDisk");
        config.setMaxBytesLocalDisk(StrUtil.obtainDefaultIfBlank(maxBytesLocalDisk, "5G"));

        CacheConfiguration cacheConfiguration = new CacheConfiguration();
        cacheConfiguration.setClassLoader(ehcacheClassloader);
        config.defaultCache(cacheConfiguration);

        CacheManager.create(config);
    }
 
Example #3
Source File: EhCacheManagerFactoryBean.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws IOException, CacheException {
	logger.info("Initializing EhCache CacheManager");
	InputStream is = this.extractEntandoConfig();
	try {
		// A bit convoluted for EhCache 1.x/2.0 compatibility.
		// To be much simpler once we require EhCache 2.1+
		if (this.cacheManagerName != null) {
			if (this.shared && createWithConfiguration == null) {
				// No CacheManager.create(Configuration) method available before EhCache 2.1;
				// can only set CacheManager name after creation.
				this.cacheManager = (is != null ? CacheManager.create(is) : CacheManager.create());
				this.cacheManager.setName(this.cacheManagerName);
			} else {
				Configuration configuration = (is != null ? ConfigurationFactory.parseConfiguration(is) :
						ConfigurationFactory.parseConfiguration());
				configuration.setName(this.cacheManagerName);
				if (this.shared) {
					this.cacheManager = (CacheManager) ReflectionUtils.invokeMethod(createWithConfiguration, null, configuration);
				} else {
					this.cacheManager = new CacheManager(configuration);
				}
			}
		} else if (this.shared) {
			// For strict backwards compatibility: use simplest possible constructors...
			this.cacheManager = (is != null ? CacheManager.create(is) : CacheManager.create());
		} else {
			this.cacheManager = (is != null ? new CacheManager(is) : new CacheManager());
		}
	} finally {
		if (is != null) {
			is.close();
		}
	}
}
 
Example #4
Source File: EhCacheManagerFactoryBean.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws CacheException {
	if (logger.isInfoEnabled()) {
		logger.info("Initializing EhCache CacheManager" +
				(this.cacheManagerName != null ? " '" + this.cacheManagerName + "'" : ""));
	}

	Configuration configuration = (this.configLocation != null ?
			EhCacheManagerUtils.parseConfiguration(this.configLocation) : ConfigurationFactory.parseConfiguration());
	if (this.cacheManagerName != null) {
		configuration.setName(this.cacheManagerName);
	}

	if (this.shared) {
		// Old-school EhCache singleton sharing...
		// No way to find out whether we actually created a new CacheManager
		// or just received an existing singleton reference.
		this.cacheManager = CacheManager.create(configuration);
	}
	else if (this.acceptExisting) {
		// EhCache 2.5+: Reusing an existing CacheManager of the same name.
		// Basically the same code as in CacheManager.getInstance(String),
		// just storing whether we're dealing with an existing instance.
		synchronized (CacheManager.class) {
			this.cacheManager = CacheManager.getCacheManager(this.cacheManagerName);
			if (this.cacheManager == null) {
				this.cacheManager = new CacheManager(configuration);
			}
			else {
				this.locallyManaged = false;
			}
		}
	}
	else {
		// Throwing an exception if a CacheManager of the same name exists already...
		this.cacheManager = new CacheManager(configuration);
	}
}
 
Example #5
Source File: CacheService.java    From lutece-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Gets the unique instance of the CacheService
 *
 * @return The unique instance of the CacheService
 */
public static synchronized CacheService getInstance( )
{
    if ( _singleton == null )
    {
        _singleton = new CacheService( );
        _singleton.init( );
        Configuration configuration = ConfigurationFactory.parseConfiguration( );
        configuration.setName( LUTECE_CACHEMANAGER_NAME );
        _manager = CacheManager.create( configuration );
    }

    return _singleton;
}
 
Example #6
Source File: CacheFactory.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
public void afterPropertiesSet() throws Exception {
    Configuration configuration = ConfigurationFactory.parseConfiguration();

    // Override configuration to make sure cache is stored in Subsonic home dir.
    File cacheDir = new File(SettingsService.getSubsonicHome(), "cache");
    configuration.getDiskStoreConfiguration().setPath(cacheDir.getPath());

    cacheManager = CacheManager.create(configuration);
}
 
Example #7
Source File: EhCache2MetricsCompatibilityTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
EhCache2MetricsCompatibilityTest() {
    Configuration config = ConfigurationFactory.parseConfiguration();
    config.setName(UUID.randomUUID().toString());

    this.cacheManager = CacheManager.newInstance(config);
    this.cacheManager.addCache("mycache");
    this.cache = cacheManager.getCache("mycache");
}
 
Example #8
Source File: CacheFactory.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
public void afterPropertiesSet() {
    Configuration configuration = ConfigurationFactory.parseConfiguration();

    // Override configuration to make sure cache is stored in Airsonic home dir.
    File cacheDir = new File(SettingsService.getAirsonicHome(), "cache");
    configuration.getDiskStoreConfiguration().setPath(cacheDir.getPath());

    cacheManager = CacheManager.create(configuration);
}
 
Example #9
Source File: EhCacheManagerFactoryBean.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws CacheException {
	if (logger.isInfoEnabled()) {
		logger.info("Initializing EhCache CacheManager" +
				(this.cacheManagerName != null ? " '" + this.cacheManagerName + "'" : ""));
	}

	Configuration configuration = (this.configLocation != null ?
			EhCacheManagerUtils.parseConfiguration(this.configLocation) : ConfigurationFactory.parseConfiguration());
	if (this.cacheManagerName != null) {
		configuration.setName(this.cacheManagerName);
	}

	if (this.shared) {
		// Old-school EhCache singleton sharing...
		// No way to find out whether we actually created a new CacheManager
		// or just received an existing singleton reference.
		this.cacheManager = CacheManager.create(configuration);
	}
	else if (this.acceptExisting) {
		// EhCache 2.5+: Reusing an existing CacheManager of the same name.
		// Basically the same code as in CacheManager.getInstance(String),
		// just storing whether we're dealing with an existing instance.
		synchronized (CacheManager.class) {
			this.cacheManager = CacheManager.getCacheManager(this.cacheManagerName);
			if (this.cacheManager == null) {
				this.cacheManager = new CacheManager(configuration);
			}
			else {
				this.locallyManaged = false;
			}
		}
	}
	else {
		// Throwing an exception if a CacheManager of the same name exists already...
		this.cacheManager = new CacheManager(configuration);
	}
}
 
Example #10
Source File: EhCacheManagerFactoryBean.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws CacheException {
	if (logger.isInfoEnabled()) {
		logger.info("Initializing EhCache CacheManager" +
				(this.cacheManagerName != null ? " '" + this.cacheManagerName + "'" : ""));
	}

	Configuration configuration = (this.configLocation != null ?
			EhCacheManagerUtils.parseConfiguration(this.configLocation) : ConfigurationFactory.parseConfiguration());
	if (this.cacheManagerName != null) {
		configuration.setName(this.cacheManagerName);
	}

	if (this.shared) {
		// Old-school EhCache singleton sharing...
		// No way to find out whether we actually created a new CacheManager
		// or just received an existing singleton reference.
		this.cacheManager = CacheManager.create(configuration);
	}
	else if (this.acceptExisting) {
		// EhCache 2.5+: Reusing an existing CacheManager of the same name.
		// Basically the same code as in CacheManager.getInstance(String),
		// just storing whether we're dealing with an existing instance.
		synchronized (CacheManager.class) {
			this.cacheManager = CacheManager.getCacheManager(this.cacheManagerName);
			if (this.cacheManager == null) {
				this.cacheManager = new CacheManager(configuration);
			}
			else {
				this.locallyManaged = false;
			}
		}
	}
	else {
		// Throwing an exception if a CacheManager of the same name exists already...
		this.cacheManager = new CacheManager(configuration);
	}
}
 
Example #11
Source File: EhCacheManagerFactoryBean.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws CacheException {
	logger.info("Initializing EhCache CacheManager");
	Configuration configuration = (this.configLocation != null ?
			EhCacheManagerUtils.parseConfiguration(this.configLocation) : ConfigurationFactory.parseConfiguration());
	if (this.cacheManagerName != null) {
		configuration.setName(this.cacheManagerName);
	}
	if (this.shared) {
		// Old-school EhCache singleton sharing...
		// No way to find out whether we actually created a new CacheManager
		// or just received an existing singleton reference.
		this.cacheManager = CacheManager.create(configuration);
	}
	else if (this.acceptExisting) {
		// EhCache 2.5+: Reusing an existing CacheManager of the same name.
		// Basically the same code as in CacheManager.getInstance(String),
		// just storing whether we're dealing with an existing instance.
		synchronized (CacheManager.class) {
			this.cacheManager = CacheManager.getCacheManager(this.cacheManagerName);
			if (this.cacheManager == null) {
				this.cacheManager = new CacheManager(configuration);
			}
			else {
				this.locallyManaged = false;
			}
		}
	}
	else {
		// Throwing an exception if a CacheManager of the same name exists already...
		this.cacheManager = new CacheManager(configuration);
	}
}
 
Example #12
Source File: EhCacheManagerUtils.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Build an EhCache {@link CacheManager} from the default configuration.
 * <p>The CacheManager will be configured from "ehcache.xml" in the root of the class path
 * (that is, default EhCache initialization - as defined in the EhCache docs - will apply).
 * If no configuration file can be found, a fail-safe fallback configuration will be used.
 * @return the new EhCache CacheManager
 * @throws CacheException in case of configuration parsing failure
 */
public static CacheManager buildCacheManager() throws CacheException {
	return new CacheManager(ConfigurationFactory.parseConfiguration());
}
 
Example #13
Source File: EhCacheManagerUtils.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Build an EhCache {@link CacheManager} from the default configuration.
 * <p>The CacheManager will be configured from "ehcache.xml" in the root of the class path
 * (that is, default EhCache initialization - as defined in the EhCache docs - will apply).
 * If no configuration file can be found, a fail-safe fallback configuration will be used.
 * @param name the desired name of the cache manager
 * @return the new EhCache CacheManager
 * @throws CacheException in case of configuration parsing failure
 */
public static CacheManager buildCacheManager(String name) throws CacheException {
	Configuration configuration = ConfigurationFactory.parseConfiguration();
	configuration.setName(name);
	return new CacheManager(configuration);
}
 
Example #14
Source File: EhCacheManagerUtils.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Build an EhCache {@link CacheManager} from the default configuration.
 * <p>The CacheManager will be configured from "ehcache.xml" in the root of the class path
 * (that is, default EhCache initialization - as defined in the EhCache docs - will apply).
 * If no configuration file can be found, a fail-safe fallback configuration will be used.
 * @return the new EhCache CacheManager
 * @throws CacheException in case of configuration parsing failure
 */
public static CacheManager buildCacheManager() throws CacheException {
	return new CacheManager(ConfigurationFactory.parseConfiguration());
}
 
Example #15
Source File: EhCacheManagerUtils.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Build an EhCache {@link CacheManager} from the default configuration.
 * <p>The CacheManager will be configured from "ehcache.xml" in the root of the class path
 * (that is, default EhCache initialization - as defined in the EhCache docs - will apply).
 * If no configuration file can be found, a fail-safe fallback configuration will be used.
 * @param name the desired name of the cache manager
 * @return the new EhCache CacheManager
 * @throws CacheException in case of configuration parsing failure
 */
public static CacheManager buildCacheManager(String name) throws CacheException {
	Configuration configuration = ConfigurationFactory.parseConfiguration();
	configuration.setName(name);
	return new CacheManager(configuration);
}
 
Example #16
Source File: EhCacheManagerUtils.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Build an EhCache {@link CacheManager} from the default configuration.
 * <p>The CacheManager will be configured from "ehcache.xml" in the root of the class path
 * (that is, default EhCache initialization - as defined in the EhCache docs - will apply).
 * If no configuration file can be found, a fail-safe fallback configuration will be used.
 * @param name the desired name of the cache manager
 * @return the new EhCache CacheManager
 * @throws CacheException in case of configuration parsing failure
 */
public static CacheManager buildCacheManager(String name) throws CacheException {
	Configuration configuration = ConfigurationFactory.parseConfiguration();
	configuration.setName(name);
	return new CacheManager(configuration);
}
 
Example #17
Source File: EhCacheManagerUtils.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Build an EhCache {@link CacheManager} from the default configuration.
 * <p>The CacheManager will be configured from "ehcache.xml" in the root of the class path
 * (that is, default EhCache initialization - as defined in the EhCache docs - will apply).
 * If no configuration file can be found, a fail-safe fallback configuration will be used.
 * @return the new EhCache CacheManager
 * @throws CacheException in case of configuration parsing failure
 */
public static CacheManager buildCacheManager() throws CacheException {
	return new CacheManager(ConfigurationFactory.parseConfiguration());
}
 
Example #18
Source File: EhCacheManagerUtils.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Build an EhCache {@link CacheManager} from the default configuration.
 * <p>The CacheManager will be configured from "ehcache.xml" in the root of the class path
 * (that is, default EhCache initialization - as defined in the EhCache docs - will apply).
 * If no configuration file can be found, a fail-safe fallback configuration will be used.
 * @param name the desired name of the cache manager
 * @return the new EhCache CacheManager
 * @throws CacheException in case of configuration parsing failure
 */
public static CacheManager buildCacheManager(String name) throws CacheException {
	Configuration configuration = ConfigurationFactory.parseConfiguration();
	configuration.setName(name);
	return new CacheManager(configuration);
}
 
Example #19
Source File: EhCacheManagerUtils.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Build an EhCache {@link CacheManager} from the default configuration.
 * <p>The CacheManager will be configured from "ehcache.xml" in the root of the class path
 * (that is, default EhCache initialization - as defined in the EhCache docs - will apply).
 * If no configuration file can be found, a fail-safe fallback configuration will be used.
 * @return the new EhCache CacheManager
 * @throws CacheException in case of configuration parsing failure
 */
public static CacheManager buildCacheManager() throws CacheException {
	return new CacheManager(ConfigurationFactory.parseConfiguration());
}