File tree Expand file tree Collapse file tree 8 files changed +16
-1
lines changed
user_service/server/src/main/java/com.solo.coderiver.user/service/impl Expand file tree Collapse file tree 8 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 22
33import org .springframework .boot .SpringApplication ;
44import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+ import org .springframework .cache .annotation .EnableCaching ;
56import org .springframework .cloud .client .discovery .EnableDiscoveryClient ;
67import org .springframework .cloud .netflix .eureka .EnableEurekaClient ;
78import org .springframework .cloud .openfeign .EnableFeignClients ;
1112@ EnableDiscoveryClient
1213@ EnableSwagger2
1314@ EnableFeignClients (basePackages = "com.solo.coderiver.user.client" )
15+ @ EnableCaching
1416public class CommentsApplication {
1517
1618 public static void main (String [] args ) {
Original file line number Diff line number Diff line change 11package com .solo .coderiver .comments .service ;
22
3- import com .solo .coderiver .comments .dataobject .CommentsInfo ;
43import com .solo .coderiver .comments .dto .CommentsInfoDTO ;
54
65import java .util .List ;
Original file line number Diff line number Diff line change 77import com .solo .coderiver .comments .service .CommentsInfoService ;
88import com .solo .coderiver .user .client .UserClient ;
99import com .solo .coderiver .user .common .UserInfoForComments ;
10+ import lombok .extern .slf4j .Slf4j ;
1011import 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 ;
1115import org .springframework .stereotype .Service ;
1216import org .springframework .util .StringUtils ;
1317
1620import java .util .stream .Collectors ;
1721
1822@ Service
23+ @ Slf4j
1924public 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 ()
Original file line number Diff line number Diff line change 1111import org .springframework .data .redis .core .Cursor ;
1212import org .springframework .data .redis .core .RedisTemplate ;
1313import org .springframework .data .redis .core .ScanOptions ;
14+ import org .springframework .data .redis .core .StringRedisTemplate ;
1415import org .springframework .stereotype .Service ;
1516
1617import java .util .ArrayList ;
You can’t perform that action at this time.
0 commit comments