springCache——jetcache缓存

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

相关推荐

  1. 缓存

    2023-12-07 00:14:01       60 阅读
  2. 缓存缓存缓存

    2023-12-07 00:14:01       30 阅读
  3. Buffer(缓冲)、Cache(缓存

    2023-12-07 00:14:01       60 阅读
  4. 缓存缓存简介

    2023-12-07 00:14:01       34 阅读
  5. Redis缓存击穿、缓存雪崩、缓存穿透

    2023-12-07 00:14:01       54 阅读
  6. http缓存?强制缓存和协商缓存

    2023-12-07 00:14:01       46 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-07 00:14:01       75 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-07 00:14:01       80 阅读
  3. 在Django里面运行非项目文件

    2023-12-07 00:14:01       64 阅读
  4. Python语言-面向对象

    2023-12-07 00:14:01       75 阅读

热门阅读

  1. Vue基础知识点梳理总结归纳

    2023-12-07 00:14:01       65 阅读
  2. HTML总结

    2023-12-07 00:14:01       54 阅读
  3. 使用Qt进行iOS编程

    2023-12-07 00:14:01       51 阅读
  4. debian12 使用技巧

    2023-12-07 00:14:01       55 阅读
  5. Linux下各种字符编码进行转码

    2023-12-07 00:14:01       44 阅读
  6. ES6模板字符串的基本使用

    2023-12-07 00:14:01       53 阅读
  7. 通过lua脚本在redis中处理json数据

    2023-12-07 00:14:01       60 阅读
  8. Clickhouse在货品标签场景的应用

    2023-12-07 00:14:01       49 阅读
  9. okhttp系列-enqueue过程

    2023-12-07 00:14:01       57 阅读
  10. 数据库的设计规范

    2023-12-07 00:14:01       53 阅读
  11. Spring Boot 升级3.x 指南

    2023-12-07 00:14:01       58 阅读
  12. 使用Feign简化Spring Boot微服务间的调用

    2023-12-07 00:14:01       55 阅读