-
实现
cn.huazai.tool.spring.cache.manager.core.CacheTemplate
接口缓存的实际执行类
eg.
@Slf4j @Component public class RedisCacheTemplateImpl implements CacheTemplate { @Resource private RedisTemplate<String, Object> redisTemplate; @Override public Object get(Object key) { return redisTemplate.opsForValue().get(key); } @Override public Boolean set(Object key, Object value, Duration timeout) { redisTemplate.opsForValue().set((String) key, value, timeout); return true; } @Override public Boolean setIfAbsent(Object key, Object value, Duration timeout) { return redisTemplate.opsForValue().setIfAbsent((String) key, value, timeout); } @Override public void delete(Object key) { redisTemplate.delete((String) key); } }
-
注入
cn.huazai.tool.spring.cache.manager.CustomCacheManager
eg.
@Slf4j @Configuration public class CacheManagerConfig { @Bean public CacheManager cacheManager(CacheTemplate cacheTemplate) { log.info("initializing cacheManager: cacheTemplate"); return new CustomCacheManager(cacheTemplate); } }
在1.1.0版本中新增了缓存名称配置错误处理策略如果你希望自定义该策略,可以使用
CustomCacheManager
的另一个构造函数eg.
@Slf4j @Configuration public class CacheManagerConfig { @Bean public CacheManager cacheManager(CacheTemplate cacheTemplate) { log.info("initializing cacheManager: cacheTemplate"); // 设置缓存名称配置错误处理策略为指定缓存时间(1分钟),后续如存在配置错误情况,则会按照1分钟缓存 return new CustomCacheManager(cacheTemplate, new MistakeSpecifiedCacheTimeStrategy("1min")); } }
-
Notifications
You must be signed in to change notification settings - Fork 0
for spring-cache @Cacheable using, Simplified use
License
YanAnHuaZai/spring-cache-manager
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Packages 0
No packages published