Search in sources :

Example 1 with PersistenceConfiguration

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

Example 2 with PersistenceConfiguration

use of net.sf.ehcache.config.PersistenceConfiguration in project ORCID-Source by ORCID.

the class OrcidEhCacheFactoryBean method createConfig.

private CacheConfiguration createConfig() {
    CacheConfiguration config = new CacheConfiguration();
    config.setName(this.cacheName);
    config.setMaxEntriesLocalHeap(this.maxElementsInMemory);
    config.setMaxElementsOnDisk(this.maxElementsOnDisk);
    config.setMaxBytesLocalDisk(this.maxBytesLocalDisk);
    config.setTimeToLiveSeconds(this.timeToLiveSeconds);
    config.setTimeToIdleSeconds(this.timeToIdleSeconds);
    config.setCopyOnRead(this.copyOnRead);
    config.setCopyOnWrite(this.copyOnWrite);
    config.persistence(new PersistenceConfiguration().strategy(this.strategy));
    return config;
}
Also used : PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 3 with PersistenceConfiguration

use of net.sf.ehcache.config.PersistenceConfiguration in project cas by apereo.

the class EhcacheTicketRegistryConfiguration method ehcacheTicketsCache.

@Lazy
@Autowired
@Bean
public EhCacheFactoryBean ehcacheTicketsCache(@Qualifier("cacheManager") final CacheManager manager) {
    final EhcacheProperties ehcacheProperties = casProperties.getTicket().getRegistry().getEhcache();
    final EhCacheFactoryBean bean = new EhCacheFactoryBean();
    bean.setCacheName(ehcacheProperties.getCacheName());
    bean.setCacheEventListeners(Collections.singleton(ticketRMISynchronousCacheReplicator()));
    bean.setTimeToIdle(ehcacheProperties.getCacheTimeToIdle());
    bean.setTimeToLive(ehcacheProperties.getCacheTimeToLive());
    bean.setCacheManager(manager);
    bean.setBootstrapCacheLoader(ticketCacheBootstrapCacheLoader());
    bean.setDiskExpiryThreadIntervalSeconds(ehcacheProperties.getDiskExpiryThreadIntervalSeconds());
    bean.setEternal(ehcacheProperties.isEternal());
    bean.setMaxEntriesLocalHeap(ehcacheProperties.getMaxElementsInMemory());
    bean.setMaxEntriesInCache(ehcacheProperties.getMaxElementsInCache());
    bean.setMaxEntriesLocalDisk(ehcacheProperties.getMaxElementsOnDisk());
    bean.setMemoryStoreEvictionPolicy(ehcacheProperties.getMemoryStoreEvictionPolicy());
    final PersistenceConfiguration c = new PersistenceConfiguration();
    c.strategy(ehcacheProperties.getPersistence());
    c.setSynchronousWrites(ehcacheProperties.isSynchronousWrites());
    bean.persistence(c);
    return bean;
}
Also used : EhCacheFactoryBean(org.springframework.cache.ehcache.EhCacheFactoryBean) PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) EhcacheProperties(org.apereo.cas.configuration.model.support.ehcache.EhcacheProperties) Lazy(org.springframework.context.annotation.Lazy) Autowired(org.springframework.beans.factory.annotation.Autowired) EhCacheFactoryBean(org.springframework.cache.ehcache.EhCacheFactoryBean) EhCacheManagerFactoryBean(org.springframework.cache.ehcache.EhCacheManagerFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)3 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)2 Strategy (net.sf.ehcache.config.PersistenceConfiguration.Strategy)1 EhcacheProperties (org.apereo.cas.configuration.model.support.ehcache.EhcacheProperties)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 EhCacheFactoryBean (org.springframework.cache.ehcache.EhCacheFactoryBean)1 EhCacheManagerFactoryBean (org.springframework.cache.ehcache.EhCacheManagerFactoryBean)1 Bean (org.springframework.context.annotation.Bean)1 Lazy (org.springframework.context.annotation.Lazy)1