Skip to content

Commit bb171dd

Browse files
committed
评论优化
1 parent be143ce commit bb171dd

File tree

8 files changed

+16
-1
lines changed

8 files changed

+16
-1
lines changed

java/comments_service/server/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070
<groupId>org.springframework.cloud</groupId>
7171
<artifactId>spring-cloud-starter-openfeign</artifactId>
7272
</dependency>
73+
74+
<dependency>
75+
<groupId>org.springframework.boot</groupId>
76+
<artifactId>spring-boot-starter-data-redis</artifactId>
77+
</dependency>
7378
</dependencies>
7479

7580
<build>

java/comments_service/server/src/main/java/com/solo/coderiver/comments/CommentsApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cache.annotation.EnableCaching;
56
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
67
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
78
import org.springframework.cloud.openfeign.EnableFeignClients;
@@ -11,6 +12,7 @@
1112
@EnableDiscoveryClient
1213
@EnableSwagger2
1314
@EnableFeignClients(basePackages = "com.solo.coderiver.user.client")
15+
@EnableCaching
1416
public class CommentsApplication {
1517

1618
public static void main(String[] args) {

java/comments_service/server/src/main/java/com/solo/coderiver/comments/service/CommentsInfoService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.solo.coderiver.comments.service;
22

3-
import com.solo.coderiver.comments.dataobject.CommentsInfo;
43
import com.solo.coderiver.comments.dto.CommentsInfoDTO;
54

65
import java.util.List;

java/comments_service/server/src/main/java/com/solo/coderiver/comments/service/impl/CommentsInfoServiceImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import com.solo.coderiver.comments.service.CommentsInfoService;
88
import com.solo.coderiver.user.client.UserClient;
99
import com.solo.coderiver.user.common.UserInfoForComments;
10+
import lombok.extern.slf4j.Slf4j;
1011
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.cache.annotation.CacheEvict;
13+
import org.springframework.cache.annotation.CachePut;
14+
import org.springframework.cache.annotation.Cacheable;
1115
import org.springframework.stereotype.Service;
1216
import org.springframework.util.StringUtils;
1317

@@ -16,6 +20,7 @@
1620
import java.util.stream.Collectors;
1721

1822
@Service
23+
@Slf4j
1924
public class CommentsInfoServiceImpl implements CommentsInfoService {
2025

2126
@Autowired
@@ -25,13 +30,16 @@ public class CommentsInfoServiceImpl implements CommentsInfoService {
2530
UserClient userClient;
2631

2732
@Override
33+
@CacheEvict(cacheNames = "comments", key = "#dto.ownerId")
2834
public CommentsInfoDTO save(CommentsInfoDTO dto) {
2935
CommentsInfo result = repository.save(CommentsConverter.DTO2Info(dto));
3036
return CommentsConverter.info2DTO(result);
3137
}
3238

3339
@Override
40+
@Cacheable(cacheNames = "comments", key = "#ownerId")
3441
public List<CommentsInfoDTO> findByOwnerId(String ownerId) {
42+
log.info("取了数据库----------");
3543
List<CommentsInfo> infoList = repository.findByOwnerId(ownerId);
3644
List<CommentsInfoDTO> list = CommentsConverter.infos2DTOList(infoList)
3745
.stream()
Binary file not shown.

java/user_service/server/src/main/java/com.solo.coderiver.user/service/impl/RedisServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.springframework.data.redis.core.Cursor;
1212
import org.springframework.data.redis.core.RedisTemplate;
1313
import org.springframework.data.redis.core.ScanOptions;
14+
import org.springframework.data.redis.core.StringRedisTemplate;
1415
import org.springframework.stereotype.Service;
1516

1617
import java.util.ArrayList;

0 commit comments

Comments
 (0)