Search in sources :

Example 26 with CacheConfiguration

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

Example 27 with CacheConfiguration

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

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

the class GoCacheTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    Cache cache = new Cache(new CacheConfiguration(getClass().getName(), 100).memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU));
    cacheManager.addCache(cache);
    this.goCache = new GoCache(cache, mock(TransactionSynchronizationManager.class));
}
Also used : CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 29 with CacheConfiguration

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

Example 30 with CacheConfiguration

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

the class CacheInformationProvider method getCacheConfigurationInformationAsJson.

public Map<String, Object> getCacheConfigurationInformationAsJson(Cache cache) {
    CacheConfiguration config = cache.getCacheConfiguration();
    LinkedHashMap<String, Object> json = new LinkedHashMap<>();
    json.put("Name", config.getName());
    json.put("Maximum Elements in Memory", config.getMaxEntriesLocalHeap());
    json.put("Maximum Elements on Disk", config.getMaxBytesLocalDisk());
    json.put("Memory Store Eviction Policy", config.getMemoryStoreEvictionPolicy().toString());
    json.put("Clean or Flush", config.isClearOnFlush());
    json.put("Eternal", config.isEternal());
    json.put("Time To Idle Seconds", config.getTimeToIdleSeconds());
    json.put("time To Live Seconds", config.getTimeToLiveSeconds());
    if (config.getPersistenceConfiguration() != null) {
        json.put("Persistence Configuration Strategy", config.getPersistenceConfiguration().getStrategy());
        json.put("Persistence Configuration Synchronous writes", config.getPersistenceConfiguration().getSynchronousWrites());
    } else {
        json.put("Persistence Configuration Strategy", "NONE");
        json.put("Persistence Configuration Synchronous writes", false);
    }
    json.put("Disk Spool Buffer Size in MB", config.getDiskSpoolBufferSizeMB());
    json.put("Disk Access Stripes", config.getDiskAccessStripes());
    json.put("Disk Expiry Thread Interval Seconds", config.getDiskExpiryThreadIntervalSeconds());
    json.put("Logging Enabled", config.getLogging());
    json.put("Terracotta Configuration", config.getTerracottaConfiguration());
    json.put("Cache Writer Configuration", config.getCacheWriterConfiguration());
    json.put("Cache Loader Configurations", config.getCacheLoaderConfigurations());
    json.put("Frozen", config.isFrozen());
    json.put("Transactional Mode", config.getTransactionalMode());
    json.put("Statistics Enabled", config.getStatistics());
    return json;
}
Also used : CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) LinkedHashMap(java.util.LinkedHashMap)

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