Search in sources :

Example 21 with Configuration

use of net.sf.ehcache.config.Configuration in project hibernate-orm by hibernate.

the class SingletonEhCacheRegionFactory method start.

@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
    this.settings = settings;
    try {
        String configurationResourceName = null;
        if (properties != null) {
            configurationResourceName = (String) properties.get(NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME);
        }
        if (configurationResourceName == null || configurationResourceName.length() == 0) {
            manager = CacheManager.create();
            REFERENCE_COUNT.incrementAndGet();
        } else {
            URL url;
            try {
                url = new URL(configurationResourceName);
            } catch (MalformedURLException e) {
                if (!configurationResourceName.startsWith("/")) {
                    configurationResourceName = "/" + configurationResourceName;
                    LOG.debugf("prepending / to %s. It should be placed in the root of the classpath rather than in a package.", configurationResourceName);
                }
                url = loadResource(configurationResourceName);
            }
            final Configuration configuration = HibernateEhcacheUtils.loadAndCorrectConfiguration(url);
            manager = CacheManager.create(configuration);
            REFERENCE_COUNT.incrementAndGet();
        }
        mbeanRegistrationHelper.registerMBean(manager, properties);
    } catch (net.sf.ehcache.CacheException e) {
        throw new CacheException(e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Configuration(net.sf.ehcache.config.Configuration) CacheException(org.hibernate.cache.CacheException) URL(java.net.URL)

Example 22 with Configuration

use of net.sf.ehcache.config.Configuration in project spring-framework by spring-projects.

the class EhCacheCacheTests method setUp.

@Before
public void setUp() {
    cacheManager = new CacheManager(new Configuration().name("EhCacheCacheTests").defaultCache(new CacheConfiguration("default", 100)));
    nativeCache = new net.sf.ehcache.Cache(new CacheConfiguration(CACHE_NAME, 100));
    cacheManager.addCache(nativeCache);
    cache = new EhCacheCache(nativeCache);
}
Also used : CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Before(org.junit.Before)

Example 23 with Configuration

use of net.sf.ehcache.config.Configuration in project spring-framework by spring-projects.

the class EhCacheManagerUtils method buildCacheManager.

/**
	 * 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);
}
Also used : Configuration(net.sf.ehcache.config.Configuration) CacheManager(net.sf.ehcache.CacheManager)

Example 24 with Configuration

use of net.sf.ehcache.config.Configuration in project libresonic by Libresonic.

the class CacheFactory method afterPropertiesSet.

public void afterPropertiesSet() throws Exception {
    Configuration configuration = ConfigurationFactory.parseConfiguration();
    // Override configuration to make sure cache is stored in Libresonic home dir.
    File cacheDir = new File(SettingsService.getLibresonicHome(), "cache");
    configuration.getDiskStoreConfiguration().setPath(cacheDir.getPath());
    cacheManager = CacheManager.create(configuration);
}
Also used : Configuration(net.sf.ehcache.config.Configuration) File(java.io.File)

Example 25 with Configuration

use of net.sf.ehcache.config.Configuration in project gocd by gocd.

the class UserCacheFactory method createCacheManager.

private CacheManager createCacheManager() {
    Configuration configuration = new Configuration();
    configuration.setDefaultCacheConfiguration(new CacheConfiguration("cache", 10000));
    return new CacheManager(configuration);
}
Also used : CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Aggregations

Configuration (net.sf.ehcache.config.Configuration)33 CacheManager (net.sf.ehcache.CacheManager)18 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)15 URL (java.net.URL)10 Test (org.junit.Test)9 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)7 Ehcache (net.sf.ehcache.Ehcache)5 IOException (java.io.IOException)4 Cache (net.sf.ehcache.Cache)4 CacheException (org.hibernate.cache.CacheException)4 File (java.io.File)3 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)3 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)3 CacheService (org.apache.directory.server.core.api.CacheService)3 InstanceLayout (org.apache.directory.server.core.api.InstanceLayout)3 Provides (com.google.inject.Provides)2 Singleton (com.google.inject.Singleton)2 MalformedURLException (java.net.MalformedURLException)2 NormalizingComparator (org.apache.directory.api.ldap.model.schema.comparators.NormalizingComparator)2 ComparatorRegistry (org.apache.directory.api.ldap.model.schema.registries.ComparatorRegistry)2