1.evict cache when tag update

main
Gary 9 months ago
parent 9a07f5b1ad
commit f140b04918

@ -64,6 +64,28 @@
<groupId>software.amazon.awssdk</groupId> <groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId> <artifactId>s3</artifactId>
</dependency> </dependency>
<dependency>
<groupId>net.oschina.j2cache</groupId>
<artifactId>j2cache-spring-boot2-starter</artifactId>
<version>2.8.0-release</version>
</dependency>
<!-- j2cache依赖 -->
<dependency>
<groupId>net.oschina.j2cache</groupId>
<artifactId>j2cache-core</artifactId>
<version>2.8.0-release</version>
<!-- 排除 -->
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>app</finalName> <finalName>app</finalName>

@ -7,6 +7,9 @@ import com.luoo.tag.service.TagS3Service;
import com.luoo.tag.service.TagService; import com.luoo.tag.service.TagService;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.oschina.j2cache.CacheChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -24,7 +27,8 @@ import java.util.List;
public class TagInfoController { public class TagInfoController {
private final TagService tagService; private final TagService tagService;
private final TagS3Service s3Service; private final TagS3Service s3Service;
private final CacheChannel cacheChannel;
@ApiOperation(value = "查询标签信息", notes = "查询标签信息") @ApiOperation(value = "查询标签信息", notes = "查询标签信息")
@GetMapping("/list") @GetMapping("/list")
public Result<PageResult<TagDTO>> page(@Validated TagQueryReq queryReq) { public Result<PageResult<TagDTO>> page(@Validated TagQueryReq queryReq) {
@ -41,6 +45,7 @@ public class TagInfoController {
@ApiOperation(value = "新增标签信息", notes = "新增标签信息") @ApiOperation(value = "新增标签信息", notes = "新增标签信息")
@PostMapping @PostMapping
public Result<Void> create(@Validated @RequestBody TagCreateReq createReq) { public Result<Void> create(@Validated @RequestBody TagCreateReq createReq) {
cacheChannel.evict("default", "search_category");
tagService.create(createReq); tagService.create(createReq);
return Result.success(); return Result.success();
} }
@ -50,6 +55,7 @@ public class TagInfoController {
@ApiImplicitParam(name = "id", value = "标签ID", required = true) }) @ApiImplicitParam(name = "id", value = "标签ID", required = true) })
@PutMapping("/{id}") @PutMapping("/{id}")
public Result<Void> update(@Validated @RequestBody TagUpdateReq updateReq, @PathVariable String id) { public Result<Void> update(@Validated @RequestBody TagUpdateReq updateReq, @PathVariable String id) {
cacheChannel.evict("default", "search_category");
updateReq.setId(id); updateReq.setId(id);
tagService.update(updateReq); tagService.update(updateReq);
return Result.success(); return Result.success();
@ -61,6 +67,7 @@ public class TagInfoController {
@ApiImplicitParam(name = "state", value = "标签状态", required = true) }) @ApiImplicitParam(name = "state", value = "标签状态", required = true) })
@PutMapping("/status/{id}") @PutMapping("/status/{id}")
public Result<Void> updateStatus(@PathVariable String id, @RequestParam Integer state) { public Result<Void> updateStatus(@PathVariable String id, @RequestParam Integer state) {
cacheChannel.evict("default", "search_category");
tagService.updateState(id, state); tagService.updateState(id, state);
return Result.success(); return Result.success();
} }
@ -71,6 +78,7 @@ public class TagInfoController {
@ApiImplicitParam(name = "show", value = "是否显示", required = true) }) @ApiImplicitParam(name = "show", value = "是否显示", required = true) })
@PutMapping("/show/{id}") @PutMapping("/show/{id}")
public Result<Void> updateShow(@PathVariable String id, @RequestParam Integer show) { public Result<Void> updateShow(@PathVariable String id, @RequestParam Integer show) {
cacheChannel.evict("default", "search_category");
tagService.updateIsShow(id, show); tagService.updateIsShow(id, show);
return Result.success(); return Result.success();
} }
@ -79,6 +87,7 @@ public class TagInfoController {
@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "标签ID", required = true) }) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "标签ID", required = true) })
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public Result<Void> delete(@PathVariable String id) { public Result<Void> delete(@PathVariable String id) {
cacheChannel.evict("default", "search_category");
tagService.delete(id); tagService.delete(id);
return Result.success(); return Result.success();
} }
@ -104,6 +113,7 @@ public class TagInfoController {
@ApiOperation(value = "上传封面", notes = "上传封面") @ApiOperation(value = "上传封面", notes = "上传封面")
@RequestMapping(value = "/upload/image", method = RequestMethod.POST) @RequestMapping(value = "/upload/image", method = RequestMethod.POST)
public Result batchUpload(@ApiParam(value = "封面图片文件", required = true) @RequestParam("file") MultipartFile file) { public Result batchUpload(@ApiParam(value = "封面图片文件", required = true) @RequestParam("file") MultipartFile file) {
cacheChannel.evict("default", "search_category");
return s3Service.upload(file); return s3Service.upload(file);
} }
} }

@ -5,4 +5,45 @@ spring:
profile: dev profile: dev
label: master label: master
uri: http://116.62.145.60:12000 uri: http://116.62.145.60:12000
# uri: http://127.0.0.1:12000 # uri: http://127.0.0.1:12000
redis:
# 地址, 多个地址使用‘,’逗号分割
hosts: ${spring.redis.host}:${spring.redis.port}
password: ${spring.redis.password}
j2cache:
openSpringCache: true
# 缓存中不存在时,运行缓存空对象
allowNullValues: true
redisClient: lettuce
l2CacheOpen: true
serialization: json
sync_ttl_to_redis: true
# 一级缓存使用caffeine
L1:
provider_class: caffeine
L2:
#使用springRedis替换二级缓存
provider_class: net.oschina.j2cache.cache.support.redis.SpringRedisProvider
config_section: redis
#使用springRedis进行广播通知缓失效
broadcast: net.oschina.j2cache.cache.support.redis.SpringRedisPubSubPolicy
# 上面配置的一级缓存为caffeine, 那么这里对一级缓存的配置就必须以这个caffeine开头
caffeine:
region:
default: 100000, 365d
journal_query_page: 10000, 365d
journal_id: 2000, 365d
journal_no: 2000, 365d
journal_song_key: 10000, 365d
journal_song_list: 2000, 365d
search_auto_complete: 200000, 365d
user_info: 20000, 365d
#caffeine:
# properties: caffeine.properties
---
spring:
cache:
# 一级缓存使用caffeine
type: caffeine
Loading…
Cancel
Save