Search in sources :

Example 6 with EhcacheCachingProvider

use of org.ehcache.jsr107.EhcacheCachingProvider in project oncotree by cBioPortal.

the class OncoTreeAppConfig method cachingProvider.

@Bean
public CachingProvider cachingProvider() throws Exception {
    logger.info("cachingProvider() called");
    CachingProvider cachingProvider = new EhcacheCachingProvider();
    return cachingProvider;
}
Also used : EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Bean(org.springframework.context.annotation.Bean)

Example 7 with EhcacheCachingProvider

use of org.ehcache.jsr107.EhcacheCachingProvider in project cas by apereo.

the class Ehcache3TicketRegistryConfiguration method ehcache3TicketCacheManager.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnMissingBean(name = "ehcache3TicketCacheManager")
public CacheManager ehcache3TicketCacheManager(final ConfigurableApplicationContext applicationContext, @Qualifier("ehcache3CacheManagerConfiguration") final ServiceCreationConfiguration ehcache3CacheManagerConfiguration, final CasConfigurationProperties casProperties) {
    return BeanSupplier.of(CacheManager.class).when(CONDITION.given(applicationContext.getEnvironment())).supply(() -> {
        val ehcacheProperties = casProperties.getTicket().getRegistry().getEhcache3();
        val ehcacheProvider = (EhcacheCachingProvider) Caching.getCachingProvider(EhcacheCachingProvider.class.getName());
        val statisticsAllEnabled = ehcacheProperties.isEnableStatistics() ? ConfigurationElementState.ENABLED : ConfigurationElementState.DISABLED;
        val managementEnabled = ehcacheProperties.isEnableManagement() ? ConfigurationElementState.ENABLED : ConfigurationElementState.DISABLED;
        val jsr107Config = new Jsr107Configuration(null, new HashMap<>(), false, managementEnabled, statisticsAllEnabled);
        val configuration = new DefaultConfiguration(ehcacheProvider.getDefaultClassLoader(), ehcache3CacheManagerConfiguration, jsr107Config);
        return ehcacheProvider.getCacheManager(ehcacheProvider.getDefaultURI(), configuration);
    }).otherwiseProxy().get();
}
Also used : lombok.val(lombok.val) Jsr107Configuration(org.ehcache.jsr107.config.Jsr107Configuration) DefaultConfiguration(org.ehcache.core.config.DefaultConfiguration) EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 8 with EhcacheCachingProvider

use of org.ehcache.jsr107.EhcacheCachingProvider in project CzechIdMng by bcvsolutions.

the class ClusteredEhCacheConfiguration method ehCacheManager.

/**
 * Defines clustered {@link CacheManager} using Terracotta server.
 *
 * @param terracotaUrl a list of IP addresses with ports (IP_ADDR:PORT)
 * @param terracotaResourceName name of server resource to connect
 * @param terracotaResourcePoolName name od server resource pool name
 * @param terracotaResourcePoolSize size of server resource pool in MB
 * @param idMCacheConfigurations a list of {@link IdMCacheConfiguration} defined in container
 * @return CacheManager with distributed capabilities
 */
@Bean
@Qualifier("jCacheManager")
@ConditionalOnProperty(value = TERRACOTA_URL_PROPERTY)
@ConditionalOnMissingBean
public CacheManager ehCacheManager(@Value("${" + TERRACOTA_URL_PROPERTY + "}") String terracotaUrl, @Value("${" + TERRACOTA_RESOURCE_NAME_PROPERTY + "}") String terracotaResourceName, @Value("${" + TERRACOTA_RESOURCE_POOL_NAME_PROPERTY + "}") String terracotaResourcePoolName, @Value("${" + TERRACOTA_RESOURCE_POOL_SIZE_PROPERTY + "}") int terracotaResourcePoolSize, @Autowired List<IdMCacheConfiguration> idMCacheConfigurations) {
    CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder().with(ClusteringServiceConfigurationBuilder.cluster(parseServerAddresses(terracotaUrl), "default").autoCreate(server -> server.defaultServerResource(terracotaResourceName).resourcePool(terracotaResourcePoolName, terracotaResourcePoolSize, MemoryUnit.MB, terracotaResourceName))).withSerializer(CacheObjectWrapper.class, CacheWrapperSerializer.class).withSerializer(SerializableCacheObjectWrapper.class, SerializableCacheWrapperSerializer.class);
    PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true);
    // create caches using IdMCacheConfiguration instances
    if (!CollectionUtils.isEmpty(idMCacheConfigurations)) {
        for (IdMCacheConfiguration config : idMCacheConfigurations) {
            cacheManager.createCache(config.getCacheName(), toConcreteConfiguration(config, terracotaResourcePoolName));
        }
    }
    // get CacheManager (Jcache) with above updated configuration
    final EhcacheCachingProvider ehcacheCachingProvider = (EhcacheCachingProvider) Caching.getCachingProvider();
    return ehcacheCachingProvider.getCacheManager(ehcacheCachingProvider.getDefaultURI(), cacheManager.getRuntimeConfiguration());
}
Also used : Arrays(java.util.Arrays) ExpiryPolicyBuilder(org.ehcache.config.builders.ExpiryPolicyBuilder) ResourcePoolsBuilder(org.ehcache.config.builders.ResourcePoolsBuilder) Autowired(org.springframework.beans.factory.annotation.Autowired) CacheConfiguration(org.ehcache.config.CacheConfiguration) Value(org.springframework.beans.factory.annotation.Value) ClusteringServiceConfigurationBuilder(org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder) EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Order(org.springframework.core.annotation.Order) MemoryUnit(org.ehcache.config.units.MemoryUnit) SerializableCacheObjectWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.SerializableCacheObjectWrapper) CacheManagerBuilder(org.ehcache.config.builders.CacheManagerBuilder) Caching(javax.cache.Caching) IdMCacheConfiguration(eu.bcvsolutions.idm.core.api.config.cache.IdMCacheConfiguration) PersistentCacheManager(org.ehcache.PersistentCacheManager) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) ClusteredResourcePoolBuilder(org.ehcache.clustered.client.config.builders.ClusteredResourcePoolBuilder) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) CacheConfigurationBuilder(org.ehcache.config.builders.CacheConfigurationBuilder) CollectionUtils(org.springframework.util.CollectionUtils) CacheManager(javax.cache.CacheManager) Bean(org.springframework.context.annotation.Bean) CacheObjectWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.CacheObjectWrapper) SerializableCacheObjectWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.SerializableCacheObjectWrapper) CacheObjectWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.CacheObjectWrapper) PersistentCacheManager(org.ehcache.PersistentCacheManager) IdMCacheConfiguration(eu.bcvsolutions.idm.core.api.config.cache.IdMCacheConfiguration) EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Example 9 with EhcacheCachingProvider

use of org.ehcache.jsr107.EhcacheCachingProvider in project CzechIdMng by bcvsolutions.

the class InMemoryEhCacheConfiguration method ehCacheManager.

/**
 * Defines in-memory cache manager.
 *
 * @param idMCacheConfigurations {@link List} of {@link IdMCacheConfiguration} defined in container
 * @return CacheManager with on-heap capabilities
 */
@Bean
@Qualifier("jCacheManager")
@ConditionalOnMissingBean
public CacheManager ehCacheManager(@Autowired List<IdMCacheConfiguration> idMCacheConfigurations) {
    CacheManagerBuilder<?> localCacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
    if (!CollectionUtils.isEmpty(idMCacheConfigurations)) {
        for (IdMCacheConfiguration config : idMCacheConfigurations) {
            localCacheManagerBuilder = localCacheManagerBuilder.withCache(config.getCacheName(), toConcreteConfiguration(config));
        }
    }
    // get CacheManager (Jcache) with above updated configuration
    final EhcacheCachingProvider ehcacheCachingProvider = (EhcacheCachingProvider) Caching.getCachingProvider();
    return ehcacheCachingProvider.getCacheManager(ehcacheCachingProvider.getDefaultURI(), localCacheManagerBuilder.build(true).getRuntimeConfiguration());
}
Also used : IdMCacheConfiguration(eu.bcvsolutions.idm.core.api.config.cache.IdMCacheConfiguration) EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 10 with EhcacheCachingProvider

use of org.ehcache.jsr107.EhcacheCachingProvider in project toy by gmoon92.

the class EhCacheConfig method createManager.

@Bean
public CacheManager createManager() {
    CachingProvider provider = new EhcacheCachingProvider();
    CacheManager manager = provider.getCacheManager();
    // config
    // MutableConfiguration configuration = new MutableConfiguration<Long, Member>()
    MutableConfiguration configuration = new MutableConfiguration().setStoreByValue(false).setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ONE_MINUTE));
    // listener config
    MutableCacheEntryListenerConfiguration listenerConfiguration = new MutableCacheEntryListenerConfiguration(FactoryBuilder.factoryOf(CacheEventLoggerListener.class), null, true, true);
    configuration.addCacheEntryListenerConfiguration(listenerConfiguration);
    // add cache
    manager.createCache(MEMBER_ALL, configuration);
    manager.createCache(MEMBER_FIND_BY_ID, configuration);
    return manager;
}
Also used : MutableCacheEntryListenerConfiguration(javax.cache.configuration.MutableCacheEntryListenerConfiguration) CacheManager(javax.cache.CacheManager) EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) MutableConfiguration(javax.cache.configuration.MutableConfiguration) EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Bean(org.springframework.context.annotation.Bean)

Aggregations

EhcacheCachingProvider (org.ehcache.jsr107.EhcacheCachingProvider)13 Bean (org.springframework.context.annotation.Bean)8 CacheManager (javax.cache.CacheManager)7 CachingProvider (javax.cache.spi.CachingProvider)7 DefaultConfiguration (org.ehcache.core.config.DefaultConfiguration)7 DefaultPersistenceConfiguration (org.ehcache.impl.config.persistence.DefaultPersistenceConfiguration)6 File (java.io.File)3 IOException (java.io.IOException)3 MutableConfiguration (javax.cache.configuration.MutableConfiguration)3 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)3 IdMCacheConfiguration (eu.bcvsolutions.idm.core.api.config.cache.IdMCacheConfiguration)2 MutableCacheEntryListenerConfiguration (javax.cache.configuration.MutableCacheEntryListenerConfiguration)2 Test (org.junit.Test)2 Qualifier (org.springframework.beans.factory.annotation.Qualifier)2 CacheConfig (de.cronn.jira.sync.config.CacheConfig)1 CacheObjectWrapper (eu.bcvsolutions.idm.core.api.config.cache.domain.CacheObjectWrapper)1 SerializableCacheObjectWrapper (eu.bcvsolutions.idm.core.api.config.cache.domain.SerializableCacheObjectWrapper)1 Field (java.lang.reflect.Field)1 InetSocketAddress (java.net.InetSocketAddress)1 Arrays (java.util.Arrays)1