【7.0.1】【cache】更新缓存的封装

pull/3/head
fengshuonan 2021-02-24 22:27:37 +08:00
parent fa7cbe7bd4
commit e4abc49d3c
7 changed files with 140 additions and 6 deletions

View File

@ -33,4 +33,14 @@ public interface CacheConstants {
*/ */
Long DEFAULT_CACHE_TIMEOUT = 1000L * 60 * 10; Long DEFAULT_CACHE_TIMEOUT = 1000L * 60 * 10;
/**
* object
*/
String DEFAULT_OBJECT_CACHE_PREFIX = "DEFAULT:OBJECTS:";
/**
* String
*/
String DEFAULT_STRING_CACHE_PREFIX = "DEFAULT:STRINGS:";
} }

View File

@ -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;
/**
* valueObject
*
* @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;
}
}

View File

@ -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;
/**
* valueString
*
* @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;
}
}

View File

@ -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;
/**
* redisvalueObject
*
* @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;
}
}

View File

@ -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;
/**
* redisvalueString
*
* @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;
}
}

View File

@ -3,6 +3,8 @@ package cn.stylefeng.roses.kernel.cache.starter.memory;
import cn.hutool.cache.CacheUtil; import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache; import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants; 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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -16,25 +18,27 @@ import org.springframework.context.annotation.Configuration;
public class GunsMemoryCacheAutoConfiguration { public class GunsMemoryCacheAutoConfiguration {
/** /**
* valuestring * valuestring
* *
* @author fengshuonan * @author fengshuonan
* @date 2021/1/31 20:39 * @date 2021/1/31 20:39
*/ */
@Bean @Bean
public TimedCache<String, String> stringTimedCache() { public DefaultStringMemoryCacheOperator defaultStringMemoryCacheOperator() {
return CacheUtil.newTimedCache(CacheConstants.DEFAULT_CACHE_TIMEOUT); TimedCache<String, String> stringTimedCache = CacheUtil.newTimedCache(CacheConstants.DEFAULT_CACHE_TIMEOUT);
return new DefaultStringMemoryCacheOperator(stringTimedCache);
} }
/** /**
* valueobject * valueobject
* *
* @author fengshuonan * @author fengshuonan
* @date 2021/1/31 20:39 * @date 2021/1/31 20:39
*/ */
@Bean @Bean
public TimedCache<String, Object> objectTimedCache() { public DefaultMemoryCacheOperator defaultMemoryCacheOperator() {
return CacheUtil.newTimedCache(CacheConstants.DEFAULT_CACHE_TIMEOUT); TimedCache<String, Object> objectTimedCache = CacheUtil.newTimedCache(CacheConstants.DEFAULT_CACHE_TIMEOUT);
return new DefaultMemoryCacheOperator(objectTimedCache);
} }
} }

View File

@ -1,5 +1,7 @@
package cn.stylefeng.roses.kernel.cache.starter.redis; 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 cn.stylefeng.roses.kernel.cache.serializer.FastJson2JsonRedisSerializer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -64,4 +66,26 @@ public class GunsRedisCacheAutoConfiguration {
return template; return template;
} }
/**
* valuestringredis
*
* @author fengshuonan
* @date 2021/1/31 20:39
*/
@Bean
public DefaultStringRedisCacheOperator defaultStringRedisCacheOperator(RedisTemplate<String, String> stringRedisTemplate) {
return new DefaultStringRedisCacheOperator(stringRedisTemplate);
}
/**
* valueobjectredis
*
* @author fengshuonan
* @date 2021/1/31 20:39
*/
@Bean
public DefaultRedisCacheOperator defaultRedisCacheOperator(RedisTemplate<String, Object> objectRedisTemplate) {
return new DefaultRedisCacheOperator(objectRedisTemplate);
}
} }