use of eu.bcvsolutions.idm.core.api.config.cache.IdMCacheConfiguration in project CzechIdMng by bcvsolutions.
the class DefaultIdmCacheManager method cacheValue.
@Override
public boolean cacheValue(String cacheName, Object key, Object value) {
Assert.hasText(cacheName, EMPTY_NAME_MSG);
Assert.notNull(key, EMPTY_KEY_MSG);
//
final Cache<Object, Object> cache = jCacheManager.getCache(cacheName);
final IdMCacheConfiguration configuration = cacheConfigurations.get(cacheName);
// We can cast here safely, because DistributedIdMCacheConfiguration only allows Serializable types
final Object toCache = isConfigLocalOnly(configuration) ? new CacheObjectWrapper<>(value) : new SerializableCacheObjectWrapper<>((Serializable) value);
if (cache != null) {
cache.put(key, toCache);
}
return cache != null && Objects.equals(cache.get(key), toCache);
}
use of eu.bcvsolutions.idm.core.api.config.cache.IdMCacheConfiguration in project CzechIdMng by bcvsolutions.
the class DefaultIdmCacheManager method getValue.
@Override
public ValueWrapper getValue(String cacheName, Object key) {
Assert.hasText(cacheName, EMPTY_NAME_MSG);
Assert.notNull(key, EMPTY_KEY_MSG);
//
Cache<Object, Object> cache = jCacheManager.getCache(cacheName);
IdMCacheConfiguration cacheConfiguration = cacheConfigurations.get(cacheName);
//
if (cache == null) {
return null;
}
//
return toValueWrapper(cacheConfiguration, cache.get(key));
}
use of eu.bcvsolutions.idm.core.api.config.cache.IdMCacheConfiguration 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());
}
use of eu.bcvsolutions.idm.core.api.config.cache.IdMCacheConfiguration 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());
}
Aggregations