-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from KTB16Team/feature/90-caching-list-api
Feature/90 caching list api
- Loading branch information
Showing
8 changed files
with
127 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
backend/src/main/java/aimo/backend/common/dto/PageResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package aimo.backend.common.dto; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.domain.Page; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PageResponse<T> { | ||
private List<T> content; | ||
private int currentPage; | ||
private int totalPages; | ||
private long totalItems; | ||
|
||
private PageResponse(List<T> content, int number, int totalPages, long totalElements) { | ||
this.content = content; | ||
this.currentPage = number; | ||
this.totalPages = totalPages; | ||
this.totalItems = totalElements; | ||
} | ||
|
||
public static <T> PageResponse<T> from(Page<T> page) { | ||
return new PageResponse<>( | ||
page.getContent(), | ||
page.getNumber(), | ||
page.getTotalPages(), | ||
page.getTotalElements() | ||
); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
backend/src/main/java/aimo/backend/common/redis/RedisCacheConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package aimo.backend.common.redis; | ||
|
||
import java.time.Duration; | ||
|
||
import org.springframework.boot.autoconfigure.cache.RedisCacheManagerBuilderCustomizer; | ||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; | ||
import org.springframework.data.redis.serializer.RedisSerializationContext; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
@Configuration | ||
@EnableCaching // Spring Boot의 캐싱 설정을 활성화 | ||
public class RedisCacheConfig { | ||
|
||
// 기본 캐시 전략 | ||
@Bean | ||
public RedisCacheConfiguration redisCacheConfiguration() { | ||
return RedisCacheConfiguration.defaultCacheConfig() | ||
.entryTtl(Duration.ofMinutes(1)) // TTL 설정 | ||
.disableCachingNullValues() // null 값 캐싱 방지 | ||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) | ||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer( | ||
new GenericJackson2JsonRedisSerializer(new ObjectMapper()) // Custom ObjectMapper 사용 | ||
)); | ||
} | ||
|
||
// 커스텀 캐시 전략 | ||
@Bean | ||
public RedisCacheManagerBuilderCustomizer redisCacheManagerBuilderCustomizer() { | ||
return (builder) -> builder | ||
.withCacheConfiguration("shortTermCache", | ||
RedisCacheConfiguration.defaultCacheConfig() | ||
.entryTtl(Duration.ofMinutes(1)) // cache1에 TTL 1분 | ||
.serializeKeysWith( | ||
RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) | ||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer( | ||
new GenericJackson2JsonRedisSerializer()))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters