mirror of https://gitee.com/stylefeng/roses
【7.0.1】【cache】更新缓存的封装
parent
fa7cbe7bd4
commit
e4abc49d3c
|
@ -33,4 +33,14 @@ public interface CacheConstants {
|
|||
*/
|
||||
Long DEFAULT_CACHE_TIMEOUT = 1000L * 60 * 10;
|
||||
|
||||
/**
|
||||
* 默认object对象缓存的缓存前缀
|
||||
*/
|
||||
String DEFAULT_OBJECT_CACHE_PREFIX = "DEFAULT:OBJECTS:";
|
||||
|
||||
/**
|
||||
* 默认String对象缓存的缓存前缀
|
||||
*/
|
||||
String DEFAULT_STRING_CACHE_PREFIX = "DEFAULT:STRINGS:";
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package cn.stylefeng.roses.kernel.cache.operator;
|
||||
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.stylefeng.roses.kernel.cache.AbstractMemoryCacheOperator;
|
||||
import cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants;
|
||||
|
||||
/**
|
||||
* 默认内存缓存的实现,value存放Object类型
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/2/24 22:16
|
||||
*/
|
||||
public class DefaultMemoryCacheOperator extends AbstractMemoryCacheOperator<Object> {
|
||||
|
||||
public DefaultMemoryCacheOperator(TimedCache<String, Object> timedCache) {
|
||||
super(timedCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommonKeyPrefix() {
|
||||
return CacheConstants.DEFAULT_OBJECT_CACHE_PREFIX;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cn.stylefeng.roses.kernel.cache.operator;
|
||||
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.stylefeng.roses.kernel.cache.AbstractMemoryCacheOperator;
|
||||
import cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants;
|
||||
|
||||
/**
|
||||
* 默认内存缓存的实现,value存放String类型
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/2/24 22:16
|
||||
*/
|
||||
public class DefaultStringMemoryCacheOperator extends AbstractMemoryCacheOperator<String> {
|
||||
|
||||
public DefaultStringMemoryCacheOperator(TimedCache<String, String> timedCache) {
|
||||
super(timedCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommonKeyPrefix() {
|
||||
return CacheConstants.DEFAULT_STRING_CACHE_PREFIX;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cn.stylefeng.roses.kernel.cache.operator;
|
||||
|
||||
import cn.stylefeng.roses.kernel.cache.AbstractRedisCacheOperator;
|
||||
import cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
/**
|
||||
* 默认redis缓存的实现,value存放Object类型
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/2/24 22:16
|
||||
*/
|
||||
public class DefaultRedisCacheOperator extends AbstractRedisCacheOperator<Object> {
|
||||
|
||||
public DefaultRedisCacheOperator(RedisTemplate<String, Object> redisTemplate) {
|
||||
super(redisTemplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommonKeyPrefix() {
|
||||
return CacheConstants.DEFAULT_OBJECT_CACHE_PREFIX;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cn.stylefeng.roses.kernel.cache.operator;
|
||||
|
||||
import cn.stylefeng.roses.kernel.cache.AbstractRedisCacheOperator;
|
||||
import cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
/**
|
||||
* 默认redis缓存的实现,value存放String类型
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/2/24 22:16
|
||||
*/
|
||||
public class DefaultStringRedisCacheOperator extends AbstractRedisCacheOperator<String> {
|
||||
|
||||
public DefaultStringRedisCacheOperator(RedisTemplate<String, String> redisTemplate) {
|
||||
super(redisTemplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommonKeyPrefix() {
|
||||
return CacheConstants.DEFAULT_STRING_CACHE_PREFIX;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,8 @@ package cn.stylefeng.roses.kernel.cache.starter.memory;
|
|||
import cn.hutool.cache.CacheUtil;
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants;
|
||||
import cn.stylefeng.roses.kernel.cache.operator.DefaultMemoryCacheOperator;
|
||||
import cn.stylefeng.roses.kernel.cache.operator.DefaultStringMemoryCacheOperator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
@ -16,25 +18,27 @@ import org.springframework.context.annotation.Configuration;
|
|||
public class GunsMemoryCacheAutoConfiguration {
|
||||
|
||||
/**
|
||||
* 创建默认的value是string类型的缓存
|
||||
* 创建默认的value是string类型的内存缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/31 20:39
|
||||
*/
|
||||
@Bean
|
||||
public TimedCache<String, String> stringTimedCache() {
|
||||
return CacheUtil.newTimedCache(CacheConstants.DEFAULT_CACHE_TIMEOUT);
|
||||
public DefaultStringMemoryCacheOperator defaultStringMemoryCacheOperator() {
|
||||
TimedCache<String, String> stringTimedCache = CacheUtil.newTimedCache(CacheConstants.DEFAULT_CACHE_TIMEOUT);
|
||||
return new DefaultStringMemoryCacheOperator(stringTimedCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建默认的value是object类型的缓存
|
||||
* 创建默认的value是object类型的内存缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/31 20:39
|
||||
*/
|
||||
@Bean
|
||||
public TimedCache<String, Object> objectTimedCache() {
|
||||
return CacheUtil.newTimedCache(CacheConstants.DEFAULT_CACHE_TIMEOUT);
|
||||
public DefaultMemoryCacheOperator defaultMemoryCacheOperator() {
|
||||
TimedCache<String, Object> objectTimedCache = CacheUtil.newTimedCache(CacheConstants.DEFAULT_CACHE_TIMEOUT);
|
||||
return new DefaultMemoryCacheOperator(objectTimedCache);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package cn.stylefeng.roses.kernel.cache.starter.redis;
|
||||
|
||||
import cn.stylefeng.roses.kernel.cache.operator.DefaultRedisCacheOperator;
|
||||
import cn.stylefeng.roses.kernel.cache.operator.DefaultStringRedisCacheOperator;
|
||||
import cn.stylefeng.roses.kernel.cache.serializer.FastJson2JsonRedisSerializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -64,4 +66,26 @@ public class GunsRedisCacheAutoConfiguration {
|
|||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建默认的value是string类型的redis缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/31 20:39
|
||||
*/
|
||||
@Bean
|
||||
public DefaultStringRedisCacheOperator defaultStringRedisCacheOperator(RedisTemplate<String, String> stringRedisTemplate) {
|
||||
return new DefaultStringRedisCacheOperator(stringRedisTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建默认的value是object类型的redis缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/31 20:39
|
||||
*/
|
||||
@Bean
|
||||
public DefaultRedisCacheOperator defaultRedisCacheOperator(RedisTemplate<String, Object> objectRedisTemplate) {
|
||||
return new DefaultRedisCacheOperator(objectRedisTemplate);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue