From 063866cc3a3e7ddbd0063f459b56eb4d4dcd345b Mon Sep 17 00:00:00 2001 From: Tim <135014430+nagisa77@users.noreply.github.com> Date: Wed, 17 Sep 2025 11:52:42 +0800 Subject: [PATCH] Fix post cache keys to include pagination --- .../com/openisle/service/CommentService.java | 8 ++++---- .../java/com/openisle/service/PostService.java | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/com/openisle/service/CommentService.java b/backend/src/main/java/com/openisle/service/CommentService.java index e9456caf7..cf09f2a19 100644 --- a/backend/src/main/java/com/openisle/service/CommentService.java +++ b/backend/src/main/java/com/openisle/service/CommentService.java @@ -52,7 +52,7 @@ public class CommentService { @CacheEvict( value = CachingConfig.POST_CACHE_NAME, - key = "'latest_reply'" + allEntries = true ) @Transactional public Comment addComment(String username, Long postId, String content) { @@ -104,7 +104,7 @@ public class CommentService { @CacheEvict( value = CachingConfig.POST_CACHE_NAME, - key = "'latest_reply'" + allEntries = true ) @Transactional public Comment addReply(String username, Long parentId, String content) { @@ -241,7 +241,7 @@ public class CommentService { @CacheEvict( value = CachingConfig.POST_CACHE_NAME, - key = "'latest_reply'" + allEntries = true ) @Transactional public void deleteComment(String username, Long id) { @@ -260,7 +260,7 @@ public class CommentService { @CacheEvict( value = CachingConfig.POST_CACHE_NAME, - key = "'latest_reply'" + allEntries = true ) @Transactional public void deleteCommentCascade(Comment comment) { diff --git a/backend/src/main/java/com/openisle/service/PostService.java b/backend/src/main/java/com/openisle/service/PostService.java index 65092d0b7..36796e346 100644 --- a/backend/src/main/java/com/openisle/service/PostService.java +++ b/backend/src/main/java/com/openisle/service/PostService.java @@ -509,7 +509,7 @@ public class PostService { @Cacheable( value = CachingConfig.POST_CACHE_NAME, - key = "'latest_reply'" + key = "new org.springframework.cache.interceptor.SimpleKey('latest_reply', #categoryIds, #tagIds, #page, #pageSize)" ) public List listPostsByLatestReply(java.util.List categoryIds, java.util.List tagIds, @@ -648,7 +648,7 @@ public class PostService { */ @Cacheable( value = CachingConfig.POST_CACHE_NAME, - key = "'default'" + key = "new org.springframework.cache.interceptor.SimpleKey('default', #ids, #tids, #page, #pageSize)" ) public List defaultListPosts(List ids, List tids, Integer page, Integer pageSize){ boolean hasCategories = !CollectionUtils.isEmpty(ids); @@ -673,7 +673,7 @@ public class PostService { @CacheEvict( value = CachingConfig.POST_CACHE_NAME, - key = "'default'" + allEntries = true ) public Post approvePost(Long id) { Post post = postRepository.findById(id) @@ -713,7 +713,7 @@ public class PostService { @CacheEvict( value = CachingConfig.POST_CACHE_NAME, - key = "'default'" + allEntries = true ) public Post pinPost(Long id, String username) { Post post = postRepository.findById(id) @@ -729,7 +729,7 @@ public class PostService { @CacheEvict( value = CachingConfig.POST_CACHE_NAME, - key = "'default'" + allEntries = true ) public Post unpinPost(Long id, String username) { Post post = postRepository.findById(id) @@ -745,7 +745,7 @@ public class PostService { @CacheEvict( value = CachingConfig.POST_CACHE_NAME, - key = "'default'" + allEntries = true ) public Post closePost(Long id, String username) { Post post = postRepository.findById(id) @@ -764,7 +764,7 @@ public class PostService { @CacheEvict( value = CachingConfig.POST_CACHE_NAME, - key = "'default'" + allEntries = true ) public Post reopenPost(Long id, String username) { Post post = postRepository.findById(id) @@ -783,7 +783,7 @@ public class PostService { @CacheEvict( value = CachingConfig.POST_CACHE_NAME, - key = "'default'" + allEntries = true ) @Transactional public Post updatePost(Long id, @@ -840,7 +840,7 @@ public class PostService { @CacheEvict( value = CachingConfig.POST_CACHE_NAME, - key = "'default'" + allEntries = true ) @Transactional public void deletePost(Long id, String username) {