com.github.yiuman.citrus.support.utils.CacheUtils Maven / Gradle / Ivy
package com.github.yiuman.citrus.support.utils;
import com.github.yiuman.citrus.support.cache.Cache;
import com.github.yiuman.citrus.support.cache.InMemoryCache;
import com.github.yiuman.citrus.support.cache.RedisCache;
import org.springframework.data.redis.core.RedisTemplate;
import java.util.Optional;
/**
* 缓存工具类
*
* @author yiuman
* @date 2020/6/16
*/
public final class CacheUtils {
public CacheUtils() {
}
@SuppressWarnings("unchecked")
public static Cache systemDefaultCache() {
return Optional.ofNullable((Cache) SpringUtils.getBean(RedisCache.class))
.orElse(InMemoryCache.get());
}
@SuppressWarnings("unchecked")
public static Cache systemCache(String namespace) {
return Optional.ofNullable((Cache) SpringUtils.getBean(RedisCache.class))
.orElse(InMemoryCache.get(namespace));
}
public static InMemoryCache newInMemoryCache(String namespace) {
return InMemoryCache.get(namespace);
}
public static InMemoryCache defaultInMemoryCache() {
return InMemoryCache.get(InMemoryCache.DEFAULT_NAMESPACE);
}
public static RedisCache newRedisCache(RedisTemplate redisTemplate) {
return new RedisCache<>(redisTemplate);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy