33import com .yen .mdblog .entity .Dto .SearchRequest ;
44import com .yen .mdblog .entity .Po .Post ;
55import com .yen .mdblog .mapper .PostMapper ;
6+ import com .yen .mdblog .service .CacheService ;
67import com .yen .mdblog .service .PostService ;
78import java .util .List ;
89import lombok .extern .slf4j .Slf4j ;
@@ -16,14 +17,28 @@ public class PostServiceImpl implements PostService {
1617
1718 @ Autowired PostMapper postMapper ;
1819
19- @ Override
20- @ Cacheable (value = "authorId" , key = "#authorId" )
21- public List <Post > getPostsById (Integer authorId ) {
22- // Simulate a time-consuming database operation
23- simulateDelay ();
24- System .out .println (">>> Query slow DB get post by userId" );
25- return postMapper .findById (authorId );
26- }
20+ @ Autowired private CacheService cacheService ;
21+
22+ @ Override
23+ @ Cacheable (value = "authorId" , key = "#authorId" )
24+ public List <Post > getPostsById (Integer authorId ) {
25+ // Simulate a time-consuming database operation
26+ simulateDelay ();
27+ System .out .println (">>> Query slow DB get post by userId" );
28+ return postMapper .findById (authorId );
29+ }
30+ //
31+ // @Override
32+ // public List<Post> getPostsById(Integer authorId) {
33+ // return cacheService.cacheResult(
34+ // "authorId",
35+ // "#authorId",
36+ // () -> {
37+ // simulateDelay();
38+ // System.out.println(">>> Query slow DB get post by userId");
39+ // return postMapper.findById(authorId);
40+ // });
41+ // }
2742
2843 @ Override
2944 public List <Post > getAllPost () {
0 commit comments