Search in sources :

Example 21 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project LogHub by fbacchella.

the class NameResolver method configure.

@Override
public boolean configure(Properties properties) {
    CacheConfiguration config = properties.getDefaultCacheConfig("NameResolver", this).eternal(false).maxEntriesLocalHeap(cacheSize).timeToLiveSeconds(ttl);
    hostCache = properties.getCache(config);
    return super.configure(properties);
}
Also used : CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 22 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project Gemma by PavlidisLab.

the class CacheMonitorImpl method getStats.

@Override
public String getStats() {
    StringBuilder buf = new StringBuilder();
    String[] cacheNames = cacheManager.getCacheNames();
    Arrays.sort(cacheNames);
    // Terracotta clustered?
    TerracottaClientConfiguration terracottaConfig = cacheManager.getConfiguration().getTerracottaConfiguration();
    buf.append("Distributed caching is ");
    buf.append(terracottaConfig != null ? "enabled" : "disabled");
    buf.append(" in the configuration file");
    buf.append(terracottaConfig != null ? ". The cache server's configuration URL is at [" + terracottaConfig.getUrl() + "]" : "");
    buf.append(".<br/>");
    buf.append(cacheNames.length).append(" caches; only non-empty caches listed below.");
    // FIXME make these sortable.
    buf.append("<br/>&nbsp;To clear all caches click here: <img src='" + Settings.getRootContext() + "/images/icons/arrow_rotate_anticlockwise.png' onClick=\"clearAllCaches()\" alt='Flush caches' title='Clear caches' />&nbsp;&nbsp;");
    buf.append("<br/>&nbsp;To start statistics collection click here: <img src='" + Settings.getRootContext() + "/images/icons/arrow_rotate_anticlockwise.png' onClick=\"enableStatistics()\" alt='Enable stats' title='Enable stats' />&nbsp;&nbsp;");
    buf.append("<br/>&nbsp;To stop statistics collection click here: <img src='" + Settings.getRootContext() + "/images/icons/arrow_rotate_anticlockwise.png' onClick=\"disableStatistics()\" alt='Disable stats' title='Disable stats' />&nbsp;&nbsp;");
    buf.append("<table style='font-size:small'  ><tr>");
    String header = "<th>Name</th><th>HitRate</th><th>Hits</th><th>Misses</th><th>Count</th><th>MemHits</th><th>MemMiss</th><th>DiskHits</th><th>Evicted</th> <th>Eternal?</th><th>UseDisk?</th> <th>MaxInMem</th><th>LifeTime</th><th>IdleTime</th>";
    buf.append(header);
    buf.append("</tr>");
    int count = 0;
    for (String rawCacheName : cacheNames) {
        Cache cache = cacheManager.getCache(rawCacheName);
        Statistics statistics = cache.getStatistics();
        long objectCount = statistics.getObjectCount();
        if (objectCount == 0) {
            continue;
        }
        // a little shorter...
        String cacheName = rawCacheName.replaceFirst("ubic.gemma.model.", "u.g.m.");
        buf.append("<tr><td>").append(this.getClearCacheHtml(rawCacheName)).append(cacheName).append("</td>");
        long hits = statistics.getCacheHits();
        long misses = statistics.getCacheMisses();
        long inMemoryHits = statistics.getInMemoryHits();
        long inMemoryMisses = statistics.getInMemoryMisses();
        long onDiskHits = statistics.getOnDiskHits();
        long evictions = statistics.getEvictionCount();
        if (hits + misses > 0) {
            buf.append(this.makeTableCellForStat(String.format("%.2f", (double) hits / (hits + misses))));
        } else {
            buf.append("<td></td>");
        }
        buf.append(this.makeTableCellForStat(hits));
        buf.append(this.makeTableCellForStat(misses));
        buf.append(this.makeTableCellForStat(objectCount));
        buf.append(this.makeTableCellForStat(inMemoryHits));
        buf.append(this.makeTableCellForStat(inMemoryMisses));
        buf.append(this.makeTableCellForStat(onDiskHits));
        buf.append(this.makeTableCellForStat(evictions));
        CacheConfiguration cacheConfiguration = cache.getCacheConfiguration();
        boolean eternal = cacheConfiguration.isEternal();
        buf.append("<td>").append(eternal ? "&bull;" : "").append("</td>");
        Strategy strategy;
        strategy = cacheConfiguration.getPersistenceConfiguration() == null ? null : cacheConfiguration.getPersistenceConfiguration().getStrategy();
        buf.append("<td>").append(strategy == null || strategy.equals(Strategy.NONE) ? "" : "&bull;").append("</td>");
        buf.append("<td>").append(cacheConfiguration.getMaxEntriesLocalHeap()).append("</td>");
        if (eternal) {
            // timeouts are irrelevant.
            buf.append("<td>-</td>");
            buf.append("<td>-</td>");
        } else {
            buf.append("<td>").append(cacheConfiguration.getTimeToIdleSeconds()).append("</td>");
            buf.append("<td>").append(cacheConfiguration.getTimeToLiveSeconds()).append("</td>");
        }
        buf.append("</tr>");
        if (++count % 25 == 0) {
            buf.append("<tr>").append(header).append("</tr>");
        }
    }
    buf.append("</table>");
    return buf.toString();
}
Also used : TerracottaClientConfiguration(net.sf.ehcache.config.TerracottaClientConfiguration) Strategy(net.sf.ehcache.config.PersistenceConfiguration.Strategy) Statistics(net.sf.ehcache.Statistics) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Example 23 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project core by craftercms.

the class EhCacheStoreAdapter method addScope.

/**
 * Adds a new scope. The scope is an instance of EhCache's {@link Cache}.
 *
 * @param scope            the name of the scope
 * @param maxItemsInMemory the maximum number of items in memory, before they are evicted
 * @throws Exception
 */
@Override
public void addScope(String scope, int maxItemsInMemory) throws Exception {
    CacheConfiguration scopeConfig = new CacheConfiguration(scope, maxItemsInMemory);
    scopeManager.addCache(new Cache(scopeConfig));
}
Also used : CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Example 24 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration 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 25 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project qi4j-sdk by Qi4j.

the class EhCachePoolMixin method createCacheConfiguration.

private CacheConfiguration createCacheConfiguration(String cacheId) {
    EhCacheConfiguration conf = config.get();
    Integer maxElementsInMemory = conf.maxElementsInMemory().get();
    if (maxElementsInMemory <= 0) {
        maxElementsInMemory = 10000;
    }
    CacheConfiguration cacheConfig = new CacheConfiguration(cacheId, maxElementsInMemory);
    String transactionalMode = conf.transactionalMode().get();
    if (transactionalMode.length() > 0) {
        cacheConfig.transactionalMode(transactionalMode);
    }
    Long timeToLiveSeconds = conf.timeToLiveSeconds().get();
    if (timeToLiveSeconds > 0) {
        cacheConfig.timeToLiveSeconds(timeToLiveSeconds);
    }
    Long timeToIdleSeconds = conf.timeToIdleSeconds().get();
    if (timeToIdleSeconds > 0) {
        cacheConfig.timeToIdleSeconds(timeToIdleSeconds);
    }
    String name = conf.name().get();
    if (name.length() > 0) {
        cacheConfig.name(name);
    }
    String memoryStoreEvictionPolicy = conf.memoryStoreEvictionPolicy().get();
    if (memoryStoreEvictionPolicy.length() > 0) {
        cacheConfig.memoryStoreEvictionPolicy(memoryStoreEvictionPolicy);
    }
    Integer maxElementsOnDisk = conf.maxElementsOnDisk().get();
    if (maxElementsOnDisk > 0) {
        cacheConfig.maxElementsOnDisk(maxElementsOnDisk);
    }
    Boolean loggingEnabled = conf.loggingEnabled().get();
    if (loggingEnabled != null) {
        cacheConfig.logging(loggingEnabled);
    }
    Boolean eternal = conf.eternal().get();
    cacheConfig.eternal(eternal);
    Integer diskSpoolBufferSizeMB = conf.diskSpoolBufferSizeMB().get();
    if (diskSpoolBufferSizeMB > 0) {
        cacheConfig.diskSpoolBufferSizeMB(diskSpoolBufferSizeMB);
    }
    Long diskExpiryThreadIntervalSeconds = conf.diskExpiryThreadIntervalSeconds().get();
    if (diskExpiryThreadIntervalSeconds > 0) {
        cacheConfig.diskExpiryThreadIntervalSeconds(diskExpiryThreadIntervalSeconds);
    }
    Integer diskAccessStripes = conf.diskAccessStripes().get();
    if (diskAccessStripes > 0) {
        cacheConfig.diskAccessStripes(diskAccessStripes);
    }
    Boolean clearOnFlush = conf.clearOnFlush().get();
    if (clearOnFlush != null) {
        cacheConfig.clearOnFlush(clearOnFlush);
    }
    // Persistence Configuration
    PersistenceConfiguration persistenceConfig = new PersistenceConfiguration();
    Strategy strategy = conf.persistenceStrategy().get();
    if (strategy == null) {
        persistenceConfig.strategy(Strategy.NONE);
    } else {
        persistenceConfig.strategy(strategy);
    }
    cacheConfig.persistence(persistenceConfig);
    return cacheConfig;
}
Also used : PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) Strategy(net.sf.ehcache.config.PersistenceConfiguration.Strategy) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Aggregations

CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)71 Cache (net.sf.ehcache.Cache)26 CacheManager (net.sf.ehcache.CacheManager)16 Ehcache (net.sf.ehcache.Ehcache)14 Configuration (net.sf.ehcache.config.Configuration)14 Element (net.sf.ehcache.Element)9 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)8 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)6 Test (org.junit.Test)6 Resource (org.springframework.core.io.Resource)6 IOException (java.io.IOException)5 Bean (org.springframework.context.annotation.Bean)5 CachedResource (org.apereo.portal.utils.cache.resource.CachedResource)4 CachingResourceLoaderImpl (org.apereo.portal.utils.cache.resource.CachingResourceLoaderImpl)4 LoadedResource (org.apereo.portal.utils.cache.resource.LoadedResource)4 ResourcesElementsProvider (org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 FileReader (java.io.FileReader)3 URL (java.net.URL)3 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)3