|
| 1 | +package top.cadecode.uniboot.business.sample.controller; |
| 2 | + |
| 3 | +import io.swagger.annotations.Api; |
| 4 | +import io.swagger.annotations.ApiOperation; |
| 5 | +import lombok.RequiredArgsConstructor; |
| 6 | +import lombok.extern.slf4j.Slf4j; |
| 7 | +import org.springframework.cache.annotation.CacheEvict; |
| 8 | +import org.springframework.cache.annotation.CachePut; |
| 9 | +import org.springframework.cache.annotation.Cacheable; |
| 10 | +import org.springframework.web.bind.annotation.PostMapping; |
| 11 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 12 | +import org.springframework.web.bind.annotation.RestController; |
| 13 | +import top.cadecode.uniboot.common.plugin.cache.consts.CacheConst; |
| 14 | +import top.cadecode.uniboot.framework.annotation.ApiFormat; |
| 15 | + |
| 16 | +/** |
| 17 | + * 二级缓存测试接口 |
| 18 | + * |
| 19 | + * @author Cade Li |
| 20 | + * @date 2023/6/17 |
| 21 | + */ |
| 22 | +@ApiFormat |
| 23 | +@Slf4j |
| 24 | +@RequiredArgsConstructor |
| 25 | +@Api(tags = "二级缓存测试") |
| 26 | +@RestController |
| 27 | +@RequestMapping("demo/dl") |
| 28 | +public class DLCacheController { |
| 29 | + |
| 30 | + @ApiOperation("测试 @Cacheable") |
| 31 | + @Cacheable(cacheNames = "test", key = "'dl'", cacheManager = CacheConst.DL) |
| 32 | + @PostMapping("test_cacheable") |
| 33 | + public String testCacheable() { |
| 34 | + log.info("testCacheable 执行"); |
| 35 | + return "Cacheable"; |
| 36 | + } |
| 37 | + |
| 38 | + @ApiOperation("测试 @Cacheable null 值") |
| 39 | + @Cacheable(cacheNames = "test", key = "'dl'", cacheManager = CacheConst.DL) |
| 40 | + @PostMapping("test_cacheable_null") |
| 41 | + public String testCacheableNull() { |
| 42 | + log.info("testCacheableNull 执行"); |
| 43 | + return null; |
| 44 | + } |
| 45 | + |
| 46 | + @ApiOperation("测试 @CachePut") |
| 47 | + @CachePut(cacheNames = "test", key = "'dl'", cacheManager = CacheConst.DL) |
| 48 | + @PostMapping("test_put") |
| 49 | + public String testPut() { |
| 50 | + return "Put"; |
| 51 | + } |
| 52 | + |
| 53 | + @ApiOperation("测试 @CachePut null 值") |
| 54 | + @CachePut(cacheNames = "test", key = "'dl'", cacheManager = CacheConst.DL) |
| 55 | + @PostMapping("test_put_null") |
| 56 | + public String testPutNull() { |
| 57 | + return null; |
| 58 | + } |
| 59 | + |
| 60 | + @ApiOperation("测试 @CacheEvict") |
| 61 | + @CacheEvict(cacheNames = "test", key = "'dl'", cacheManager = CacheConst.DL) |
| 62 | + @PostMapping("test_evict") |
| 63 | + public String testEvict() { |
| 64 | + return "Evict"; |
| 65 | + } |
| 66 | +} |
0 commit comments