Search in sources :

Example 16 with Configuration

use of net.sf.ehcache.config.Configuration in project coastal-hazards by USGS-CIDA.

the class CacheResource method clearCache.

boolean clearCache() {
    boolean cleared = false;
    try {
        CacheConfiguration ehConfig = new CacheConfiguration().name(cacheName).memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU).persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP)).maxBytesLocalDisk(10, MemoryUnit.MEGABYTES).maxBytesLocalHeap(1, MemoryUnit.MEGABYTES).clearOnFlush(true);
        Configuration managerConfig = new Configuration().diskStore(new DiskStoreConfiguration().path(cacheLocation)).dynamicConfig(false).cache(ehConfig);
        CacheManager cacheManager = CacheManager.create(managerConfig);
        Ehcache ehcache = cacheManager.getEhcache(cacheName);
        if (ehcache != null) {
            ehcache.flush();
            ehcache.removeAll();
            cleared = true;
        } else {
            cleared = false;
        }
    } catch (Exception e) {
        log.debug("Unable to clear cache", e);
        cleared = false;
    }
    return cleared;
}
Also used : PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) CacheManager(net.sf.ehcache.CacheManager) Ehcache(net.sf.ehcache.Ehcache) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 17 with Configuration

use of net.sf.ehcache.config.Configuration in project coastal-hazards by USGS-CIDA.

the class CacheResourceTest method testClearCache.

/**
 * Test of clearCache method, of class CacheResource.
 */
@Test
public void testClearCache() {
    CacheConfiguration ehConfig = new CacheConfiguration().name(CACHE_NAME).memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU).persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP)).timeToLiveSeconds(1000).timeToIdleSeconds(1000).clearOnFlush(true);
    Configuration managerConfig = new Configuration().diskStore(new DiskStoreConfiguration().path(CACHE_LOCATION)).maxBytesLocalHeap(1, MemoryUnit.MEGABYTES).maxBytesLocalDisk(100, MemoryUnit.MEGABYTES).dynamicConfig(false).cache(ehConfig);
    CacheManager cacheManager = CacheManager.create(managerConfig);
    Ehcache ehcache = cacheManager.getEhcache(CACHE_NAME);
    for (int i = 0; i < 100; i++) {
        Element e = new Element(i, "value" + i);
        ehcache.put(e);
    }
    assertThat(ehcache.getSize(), is(equalTo(100)));
    CacheResource instance = new CacheResource();
    boolean cleared = instance.clearCache();
    assertThat(cleared, is(equalTo(true)));
    assertThat(ehcache.getSize(), is(equalTo(0)));
}
Also used : PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) Element(net.sf.ehcache.Element) CacheManager(net.sf.ehcache.CacheManager) Ehcache(net.sf.ehcache.Ehcache) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Test(org.junit.Test)

Example 18 with Configuration

use of net.sf.ehcache.config.Configuration in project activemq-artemis by apache.

the class InMemoryDirectoryServiceFactory method init.

/**
 * {@inheritDoc}
 */
@Override
public void init(String name) throws Exception {
    if ((directoryService == null) || directoryService.isStarted()) {
        return;
    }
    directoryService.setInstanceId(name);
    // instance layout
    InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + name);
    if (instanceLayout.getInstanceDirectory().exists()) {
        try {
            FileUtils.deleteDirectory(instanceLayout.getInstanceDirectory());
        } catch (IOException e) {
            LOG.warn("couldn't delete the instance directory before initializing the DirectoryService", e);
        }
    }
    directoryService.setInstanceLayout(instanceLayout);
    // EhCache in disabled-like-mode
    Configuration ehCacheConfig = new Configuration();
    CacheConfiguration defaultCache = new CacheConfiguration("default", 1).eternal(false).timeToIdleSeconds(30).timeToLiveSeconds(30).overflowToDisk(false);
    ehCacheConfig.addDefaultCache(defaultCache);
    CacheService cacheService = new CacheService(new CacheManager(ehCacheConfig));
    directoryService.setCacheService(cacheService);
    // Init the schema
    // SchemaLoader loader = new SingleLdifSchemaLoader();
    SchemaLoader loader = new JarLdifSchemaLoader();
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    schemaManager.loadAllEnabled();
    ComparatorRegistry comparatorRegistry = schemaManager.getComparatorRegistry();
    for (LdapComparator<?> comparator : comparatorRegistry) {
        if (comparator instanceof NormalizingComparator) {
            ((NormalizingComparator) comparator).setOnServer();
        }
    }
    directoryService.setSchemaManager(schemaManager);
    InMemorySchemaPartition inMemorySchemaPartition = new InMemorySchemaPartition(schemaManager);
    SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
    schemaPartition.setWrappedPartition(inMemorySchemaPartition);
    directoryService.setSchemaPartition(schemaPartition);
    List<Throwable> errors = schemaManager.getErrors();
    if (errors.size() != 0) {
        throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
    }
    // Init system partition
    Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), directoryService.getDnFactory(), "system", ServerDNConstants.SYSTEM_DN, 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "system"));
    systemPartition.setSchemaManager(directoryService.getSchemaManager());
    partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100);
    directoryService.setSystemPartition(systemPartition);
    directoryService.startup();
}
Also used : InstanceLayout(org.apache.directory.server.core.api.InstanceLayout) Partition(org.apache.directory.server.core.api.partition.Partition) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) JarLdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader) SchemaLoader(org.apache.directory.api.ldap.model.schema.registries.SchemaLoader) Configuration(net.sf.ehcache.config.Configuration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) NormalizingComparator(org.apache.directory.api.ldap.model.schema.comparators.NormalizingComparator) IOException(java.io.IOException) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) IOException(java.io.IOException) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) JarLdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader) CacheManager(net.sf.ehcache.CacheManager) ComparatorRegistry(org.apache.directory.api.ldap.model.schema.registries.ComparatorRegistry) File(java.io.File) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) CacheService(org.apache.directory.server.core.api.CacheService) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)

Example 19 with Configuration

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

the class InMemoryDirectoryServiceFactory method init.

/**
 * {@inheritDoc}
 */
@Override
public void init(String name) throws Exception {
    if ((directoryService == null) || directoryService.isStarted()) {
        return;
    }
    int id = counter++;
    directoryService.setInstanceId(name + id);
    // instance layout
    InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + directoryService.getInstanceId());
    if (instanceLayout.getInstanceDirectory().exists()) {
        try {
            FileUtils.deleteDirectory(instanceLayout.getInstanceDirectory());
        } catch (IOException e) {
            LOG.warn("couldn't delete the instance directory before initializing the DirectoryService", e);
        }
    }
    directoryService.setInstanceLayout(instanceLayout);
    // EhCache in disabled-like-mode
    String cacheName = "ApacheDSTestCache-" + id;
    Configuration ehCacheConfig = new Configuration();
    ehCacheConfig.setName(cacheName);
    CacheConfiguration defaultCache = new CacheConfiguration(cacheName, 1).eternal(false).timeToIdleSeconds(30).timeToLiveSeconds(30).overflowToDisk(false);
    ehCacheConfig.addDefaultCache(defaultCache);
    cacheManager = new CacheManager(ehCacheConfig);
    CacheService cacheService = new CacheService(cacheManager);
    directoryService.setCacheService(cacheService);
    // Init the schema
    // SchemaLoader loader = new SingleLdifSchemaLoader();
    SchemaLoader loader = new JarLdifSchemaLoader();
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    schemaManager.loadAllEnabled();
    ComparatorRegistry comparatorRegistry = schemaManager.getComparatorRegistry();
    for (LdapComparator<?> comparator : comparatorRegistry) {
        if (comparator instanceof NormalizingComparator) {
            ((NormalizingComparator) comparator).setOnServer();
        }
    }
    directoryService.setSchemaManager(schemaManager);
    InMemorySchemaPartition inMemorySchemaPartition = new InMemorySchemaPartition(schemaManager);
    SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
    schemaPartition.setWrappedPartition(inMemorySchemaPartition);
    directoryService.setSchemaPartition(schemaPartition);
    List<Throwable> errors = schemaManager.getErrors();
    if (errors.size() != 0) {
        throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
    }
    DnFactory dnFactory = new DefaultDnFactory(schemaManager, cacheService.getCache("dnCache"));
    // Init system partition
    Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), dnFactory, "system", ServerDNConstants.SYSTEM_DN, 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "system"));
    systemPartition.setSchemaManager(directoryService.getSchemaManager());
    partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100);
    directoryService.setSystemPartition(systemPartition);
    directoryService.startup();
}
Also used : InstanceLayout(org.apache.directory.server.core.api.InstanceLayout) Partition(org.apache.directory.server.core.api.partition.Partition) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) SchemaLoader(org.apache.directory.api.ldap.model.schema.registries.SchemaLoader) JarLdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader) Configuration(net.sf.ehcache.config.Configuration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) DefaultDnFactory(org.apache.directory.server.core.shared.DefaultDnFactory) NormalizingComparator(org.apache.directory.api.ldap.model.schema.comparators.NormalizingComparator) IOException(java.io.IOException) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) SubschemaAdministrativePoint(org.apache.directory.server.core.api.administrative.SubschemaAdministrativePoint) TriggerExecutionAdministrativePoint(org.apache.directory.server.core.api.administrative.TriggerExecutionAdministrativePoint) AccessControlAdministrativePoint(org.apache.directory.server.core.api.administrative.AccessControlAdministrativePoint) CollectiveAttributeAdministrativePoint(org.apache.directory.server.core.api.administrative.CollectiveAttributeAdministrativePoint) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) DnFactory(org.apache.directory.server.core.api.DnFactory) DefaultDnFactory(org.apache.directory.server.core.shared.DefaultDnFactory) JarLdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader) CacheManager(net.sf.ehcache.CacheManager) ComparatorRegistry(org.apache.directory.api.ldap.model.schema.registries.ComparatorRegistry) File(java.io.File) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) CacheService(org.apache.directory.server.core.api.CacheService) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)

Example 20 with Configuration

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

the class GoCacheFactory method createCache.

@Bean(name = "goCache")
public GoCache createCache() {
    CacheManager cacheManager = CacheManager.newInstance(new Configuration().name(getClass().getName()));
    Cache cache = new Cache(cacheConfiguration);
    cacheManager.addCache(cache);
    return new GoCache(cache, transactionSynchronizationManager);
}
Also used : PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) CacheManager(net.sf.ehcache.CacheManager) Cache(net.sf.ehcache.Cache) Bean(org.springframework.context.annotation.Bean)

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