org.zodiac.cache.reactive.config.ReactiveCacheInfo Maven / Gradle / Ivy
The newest version!
package org.zodiac.cache.reactive.config;
import java.util.Objects;
import org.springframework.context.ApplicationContext;
import org.springframework.core.ResolvableType;
import org.springframework.data.redis.core.ReactiveRedisOperations;
import org.zodiac.cache.reactive.ReactiveCache;
import org.zodiac.cache.reactive.ReactiveCacheManager;
import org.zodiac.cache.reactive.supports.RedisLocalReactiveCacheManager;
import org.zodiac.cache.reactive.supports.UnsupportedReactiveCache;
import org.zodiac.sdk.toolkit.util.ClassUtil;
import org.zodiac.sdk.toolkit.util.lang.StrUtil;
public class ReactiveCacheInfo {
private boolean enabled = false;
private Type type = Type.none;
private final GuavaCacheInfo guava = new GuavaCacheInfo();
private final CaffeineCacheInfo caffeine = new CaffeineCacheInfo();
private final RedisCacheInfo redis = new RedisCacheInfo();
public ReactiveCacheInfo() {
super();
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public GuavaCacheInfo getGuava() {
return guava;
}
public CaffeineCacheInfo getCaffeine() {
return caffeine;
}
public RedisCacheInfo getRedis() {
return redis;
}
public boolean anyProviderPresent() {
return ClassUtil.isPresent("com.google.common.cache.Cache", this.getClass().getClassLoader())
|| ClassUtil.isPresent("com.github.benmanes.caffeine.cache.Cache", this.getClass().getClassLoader())
|| ClassUtil.isPresent("org.springframework.data.redis.core.ReactiveRedisOperations", this.getClass().getClassLoader());
}
@SuppressWarnings("all")
public ReactiveCacheManager createCacheManager(ApplicationContext context) {
if (!anyProviderPresent()) {
return new ReactiveCacheManager() {
@Override
public ReactiveCache getCache(String name) {
return UnsupportedReactiveCache.getInstance();
}
};
}
if (type == Type.redis) {
ReactiveRedisOperations