com.github.mizool.technology.jcache.config.ConfigurableCacheManager Maven / Gradle / Ivy
package com.github.mizool.technology.jcache.config;
import javax.cache.Cache;
import javax.cache.configuration.Configuration;
import javax.cache.configuration.MutableConfiguration;
import jakarta.enterprise.event.Event;
import jakarta.inject.Inject;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import com.github.mizool.core.NonDefault;
import com.github.mizool.technology.jcache.common.AbstractDelegatingCacheManager;
@Slf4j
@NonDefault
public class ConfigurableCacheManager extends AbstractDelegatingCacheManager
{
private final Event> cacheCreationEvent;
@Inject
public ConfigurableCacheManager(@NonNull Event> cacheCreationEvent)
{
this.cacheCreationEvent = cacheCreationEvent;
}
@Override
public > Cache createCache(
String cacheName, C configuration) throws IllegalArgumentException
{
/*
* To avoid generics shenanigans we discard the given configuration and start from scratch.
* The reference implementation passes an empty configuration anyway.
*/
MutableConfiguration mutableConfiguration = new MutableConfiguration<>();
CacheCreation cacheCreation = new CacheCreation<>(cacheName, mutableConfiguration);
cacheCreationEvent.fire(cacheCreation);
return super.createCache(cacheCreation.getCacheName(), cacheCreation.getConfiguration());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy