首页>代码>Spring Boot整合Caffeine的简单入门实例>/caffeine/src/main/java/com/memorynotfound/springboot/MusicServiceIml.java
package com.memorynotfound.springboot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.*; import org.springframework.stereotype.Service; @Service @CacheConfig(cacheNames = {"directory", "instruments"}) public class MusicServiceIml implements MusicService { private static Logger log = LoggerFactory.getLogger(MusicServiceIml.class); @Cacheable(unless = "!#result.equals('paying zuidaima!')") public String play(String instrument) { log.info("Executing: " + this.getClass().getSimpleName() + ".play(\"" + instrument + "\");"); return "paying " + instrument + "!"; } @Cacheable(condition = "#instrument.equals('zuidaima')") public String play2(String instrument) { log.info("Executing: " + this.getClass().getSimpleName() + ".play(\"" + instrument + "\");"); return "paying " + instrument + "!"; } }