jetcache远程、本地缓存方案
<dependency>
<groupId>com.alicp.jetcache</groupId>
<artifactId>jetcache-starter-redis</artifactId>
<version>2.6.4</version>
</dependency>
jetcache:
local:
default:
type: linkedhashmap
keyConvertor: fastjson
remote:
default:
type: redis
host: localhost
port: 6379
password: 123456
poolConfig:
maxTotal: 50
sms:
type: redis
host: localhost
port: 6379
poolConfig:
maxTotal: 50
//remote
// @CreateCache(area="sms",name = "jetCache_",expire = 3600,timeUnit = TimeUnit.SECONDS)
@CreateCache(name = "jetCache_",expire = 3600,timeUnit = TimeUnit.SECONDS,cacheType = CacheType.LOCAL)
private Cache<String,String> jetCache;
@Override
public String sendCodeToSMS(String tele) {
String code = codeUtils.generator(tele);
jetCache.put(tele,code);
return code;
}
@Override
public Boolean checkCode(SMSCode smsCode) {
String code = jetCache.get(smsCode.getTele());
return smsCode.getCode().equals(code);
}
jetcache方法注解使用方式
@SpringBootApplication
// Jetcache启用缓存的主开关
@EnableCreateCacheAnnotation
// 开启方法注解缓存
@EnableMethodCache(basePackages = "com.itheima")
public class Springboot20JetcacheApplication {
public static void main(String[] args) {
SpringApplication.run(Springboot20JetcacheApplication.class, args);
}
}
@Override
@Cached(name = "book_",key = "#id",expire = 3600,cacheType = CacheType.REMOTE)
// @CacheRefresh(refresh = 10)
public Book getById(Integer id) {
return bookDao.selectById(id);
}
@Override
public Boolean save(Book book) {
return bookDao.insert(book)>0;
}
@Override
@CacheUpdate(name = "book_",key = "#book.id",value = "#book")
public Boolean update(Book book) {
return bookDao.updateById(book) > 0;
}
@Override
@CacheInvalidate(name = "book_",key = "#id")
public Boolean delete(Integer id) {
return bookDao.deleteById(id) > 0;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Book implements Serializable {
private Integer id;
private String type;
private String name;
private String description;
}
jetcache:
statIntervalMinutes: 1
local:
default:
type: linkedhashmap
keyConvertor: fastjson
remote:
default:
type: redis
host: localhost
port: 6379
password: 123456
keyConvertor: fastjson
valueEncode: java
valueDecode: java
poolConfig:
maxTotal: 50
sms:
type: redis
host: localhost
port: 6379
poolConfig:
maxTotal: 50
原文地址:https://blog.csdn.net/shall_zhao/article/details/134747484
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_30080.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。