zoukankan      html  css  js  c++  java
  • SpringBoot缓存 --(二)Redis单机缓存

    pom.xml

      <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-cache</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>

    application.properties

    #缓存配置
    spring.cache.cache-names=c1,c2
    spring.cache.redis.time-to-live=1800s
    #Redis配置
    spring.redis.database=0
    spring.redis.host=192.168.205.100
    spring.redis.port=6379
    spring.redis.password=123456 
    spring.redis.jedis.pool.max-active=8 
    spring.redis.jedis.pool.max-idle=8
    spring.redis.jedis.pool.max-wait=-1ms 
    spring.redis.jedis.pool.min-idle=0

    dao

    @Repository
    public class BookDao {
        @Cacheable("c1")
        public Book getBookById(Integer id) {
            System.out.println("getBookById");
            Book book = new Book();
            book.setId(id);
            book.setName("三国演义");
            book.setAuthor("罗贯中");
            return book;
        }
    }

    项目入口类开启缓存:

    @SpringBootApplication
    @EnableCaching
    public class RediscacheApplication {
        public static void main(String[] args) {
            SpringApplication.run(RediscacheApplication.class, args);
        }
    }
  • 相关阅读:
    P1017 进制转换
    P1100 高低位交换
    P1469 找筷子
    P1866 编号
    SQL常用语句(T-SQL、PL/SQL)
    Proxyer内网穿透配置教程
    使用JS检测自定义协议是否存在
    C# 代码启动ClickOnce应用
    SQL Server 异地备份到远程共享文件夹异常处理
    发布ClickOnce应用程序步骤与URL传参应用
  • 原文地址:https://www.cnblogs.com/crazy-lc/p/12358293.html
Copyright © 2011-2022 走看看