Search in sources :

Example 41 with CacheManager

use of net.sf.ehcache.CacheManager in project trainning by fernandotomasio.

the class TurmaPlanejadaFindAllInterceptor method invoke.

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    Object result = null;
    CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
    Cache cache = cacheManager.getCache("colecoesCache");
    Element element = cache.get("turmasPlanejadas");
    if (element == null) {
        result = invocation.proceed();
        cache.put(new Element("turmasPlanejadas", result));
    } else {
        result = element.getValue();
    }
    return result;
}
Also used : Element(net.sf.ehcache.Element) CacheManager(net.sf.ehcache.CacheManager) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(net.sf.ehcache.Cache)

Example 42 with CacheManager

use of net.sf.ehcache.CacheManager 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 43 with CacheManager

use of net.sf.ehcache.CacheManager in project Gemma by PavlidisLab.

the class CacheKey method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    CacheManager cacheManager = this.cacheManagerFactory.getObject();
    int maxElements = Settings.getInt("gemma.cache.vectors.maxelements", ProcessedDataVectorCacheImpl.VECTOR_CACHE_DEFAULT_MAX_ELEMENTS);
    int timeToLive = Settings.getInt("gemma.cache.vectors.timetolive", ProcessedDataVectorCacheImpl.VECTOR_CACHE_DEFAULT_TIME_TO_LIVE);
    int timeToIdle = Settings.getInt("gemma.cache.vectors.timetoidle", ProcessedDataVectorCacheImpl.VECTOR_CACHE_DEFAULT_TIME_TO_IDLE);
    boolean overFlowToDisk = Settings.getBoolean("gemma.cache.vectors.usedisk", ProcessedDataVectorCacheImpl.VECTOR_CACHE_DEFAULT_OVERFLOW_TO_DISK);
    boolean terracottaEnabled = Settings.getBoolean("gemma.cache.clustered", true);
    boolean eternal = Settings.getBoolean("gemma.cache.vectors.eternal", ProcessedDataVectorCacheImpl.VECTOR_CACHE_DEFAULT_ETERNAL) && timeToLive == 0;
    boolean diskPersistent = Settings.getBoolean("gemma.cache.diskpersistent", true) && !terracottaEnabled;
    this.cache = CacheUtils.createOrLoadCache(cacheManager, ProcessedDataVectorCacheImpl.VECTOR_CACHE_NAME, terracottaEnabled, maxElements, overFlowToDisk, eternal, timeToIdle, timeToLive, diskPersistent);
}
Also used : CacheManager(net.sf.ehcache.CacheManager)

Example 44 with CacheManager

use of net.sf.ehcache.CacheManager in project Gemma by PavlidisLab.

the class GeneTestedInCacheImpl method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    CacheManager cacheManager = cacheManagerFactory.getObject();
    assert cacheManager != null;
    // Other settings just use the gene2gene ones.
    int timeToLive = Settings.getInt("gemma.cache.gene2gene.timetolive", GeneTestedInCacheImpl.GENE_COEXPRESSIONTESTED_CACHE_DEFAULT_TIME_TO_LIVE);
    int timeToIdle = Settings.getInt("gemma.cache.gene2gene.timetoidle", GeneTestedInCacheImpl.GENE_COEXPRESSIONTESTED_CACHE_DEFAULT_TIME_TO_IDLE);
    boolean overFlowToDisk = Settings.getBoolean("gemma.cache.gene2gene.usedisk", GeneTestedInCacheImpl.GENE_COEXPRESSIONTESTED_CACHE_DEFAULT_OVERFLOW_TO_DISK);
    boolean eternal = Settings.getBoolean("gemma.cache.gene2gene.eternal", GeneTestedInCacheImpl.GENE_COEXPRESSIONTESTED_CACHE_DEFAULT_ETERNAL) && timeToLive == 0;
    boolean terracottaEnabled = Settings.getBoolean("gemma.cache.clustered", false);
    boolean diskPersistent = Settings.getBoolean("gemma.cache.diskpersistent", false) && !terracottaEnabled;
    this.cache = CacheUtils.createOrLoadCache(cacheManager, GeneTestedInCacheImpl.GENE_COEXPRESSIONTESTED_CACHE_NAME, terracottaEnabled, GeneTestedInCacheImpl.GENE_COEXPRESSIONTESTED_CACHE_DEFAULT_MAX_ELEMENTS, overFlowToDisk, eternal, timeToIdle, timeToLive, diskPersistent);
}
Also used : CacheManager(net.sf.ehcache.CacheManager)

Example 45 with CacheManager

use of net.sf.ehcache.CacheManager in project Mycat-Server by MyCATApache.

the class EnchachePooFactory method createCachePool.

@Override
public CachePool createCachePool(String poolName, int cacheSize, int expiredSeconds) {
    CacheManager cacheManager = CacheManager.create();
    Cache enCache = cacheManager.getCache(poolName);
    if (enCache == null) {
        CacheConfiguration cacheConf = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone();
        cacheConf.setName(poolName);
        if (cacheConf.getMaxEntriesLocalHeap() != 0) {
            cacheConf.setMaxEntriesLocalHeap(cacheSize);
        } else {
            cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize));
        }
        cacheConf.setTimeToIdleSeconds(expiredSeconds);
        Cache cache = new Cache(cacheConf);
        cacheManager.addCache(cache);
        return new EnchachePool(poolName, cache, cacheSize);
    } else {
        return new EnchachePool(poolName, enCache, cacheSize);
    }
}
Also used : CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Aggregations

CacheManager (net.sf.ehcache.CacheManager)102 Cache (net.sf.ehcache.Cache)55 ClassPathResource (org.springframework.core.io.ClassPathResource)21 Element (net.sf.ehcache.Element)20 Configuration (net.sf.ehcache.config.Configuration)18 Test (org.junit.Test)18 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)17 MarkupCache (org.apache.wicket.markup.MarkupCache)10 CacheException (net.sf.ehcache.CacheException)9 IOException (java.io.IOException)7 Ehcache (net.sf.ehcache.Ehcache)7 UpdatingSelfPopulatingCache (net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache)6 URL (java.net.URL)5 BlockingCache (net.sf.ehcache.constructs.blocking.BlockingCache)5 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)5 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)4 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)4 Around (org.aspectj.lang.annotation.Around)4 Before (org.junit.Before)4 File (java.io.File)3