<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                使用緩存的步驟如下: **1. 創建一個SpringBoot項目** ```xml <dependencies> <!-- Spring 緩存支持 --> <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-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.24</version> </dependency> </dependencies> ``` **2. 在啟動類上標注注解`@EnableCaching`開啟緩存支持** ```java @EnableCaching @SpringBootApplication public class Cache01Application { public static void main(String[] args) { SpringApplication.run(Cache01Application.class, args); } } ``` **3. 在Service層中調用緩存注解** ```java @Slf4j @Service public class StudentService { /** * 如果key沒有被緩存則進行緩存,方法被調用; * 如果key已被緩存則直接讀取緩存,方法沒有被調用; * 方法的返回值就是緩存的數據; */ @Cacheable(value = {"student"}, key = "#id") public Student get(Integer id) { log.info("get[001]:id={}", id); Student student = new Student(id, "張三", 25); return student; } /** * 更新緩存,無論某一個key是否被緩存,每次都會更新該緩存。 * 方法每次都會被調用,方法的返回值被更新到緩存中。 */ @CachePut(value = {"student"}, key = "#student.id") public Student update(Student student) { log.info("update[001]: {}", student); return student; } /** * 清除指定key的緩存. * 無論key是否存在方法都會被調用. */ @CacheEvict(value = {"student"}, key = "#id") public void delete(Integer id) { log.info("delete[001]:id={}", id); } /** * 定義復雜的緩存規則 */ @Caching( cacheable = { @Cacheable(value = "student", key = "#student.id") }, put = { @CachePut(value = "student", key = "#result.id", condition = "#student.id == 2"), } ) public Student getOrUpdate(Student student) { log.info("getOrUpdate[001]:{}", student); return student; } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看