Skip to content

Commit e40f352

Browse files
committed
modify: post service 계층 캐시 추가 예시
1 parent 25495ca commit e40f352

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/services/post.service.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import logger from '@/configs/logger.config';
22
import { PostRepository } from '@/repositories/post.repository';
33
import { RawPostType } from '@/types';
4-
import { cache } from '@/configs/cache.config';
4+
// import { cache } from '@/configs/cache.config';
55
import { getCurrentKSTDateString, getKSTDateStringWithOffset } from '@/utils/date.util';
66

77
export class PostService {
88
constructor(private postRepo: PostRepository) { }
99

1010
async getAllposts(userId: number, cursor?: string, sort: string = '', isAsc?: boolean, limit: number = 15) {
1111
try {
12-
const cacheKey = `posts:user:${userId}:${cursor || 'first'}:${sort}:${isAsc}:${limit}`;
13-
const cachedResult = await cache.get(cacheKey);
14-
if (cachedResult) {
15-
return cachedResult;
16-
}
12+
// const cacheKey = `posts:user:${userId}:${cursor || 'first'}:${sort}:${isAsc}:${limit}`;
13+
// const cachedResult = await cache.get(cacheKey);
14+
// if (cachedResult) {
15+
// return cachedResult;
16+
// }
1717

1818
let result = null;
1919
if (sort === 'viewGrowth') {
@@ -39,10 +39,10 @@ export class PostService {
3939
nextCursor: result.nextCursor,
4040
};
4141

42-
// 결과가 빈 값이 아니라면 캐시에 저장 (5분 TTL)
43-
if (results.posts.length > 0) {
44-
await cache.set(cacheKey, results, 300);
45-
}
42+
// // 결과가 빈 값이 아니라면 캐시에 저장 (5분 TTL)
43+
// if (results.posts.length > 0) {
44+
// await cache.set(cacheKey, results, 300);
45+
// }
4646
return results
4747
} catch (error) {
4848
logger.error('PostService getAllposts error : ', error);
@@ -52,11 +52,11 @@ export class PostService {
5252

5353
async getAllPostsStatistics(userId: number) {
5454
try {
55-
const cacheKey = `posts:stats:${userId}`;
56-
const cachedResult = await cache.get(cacheKey);
57-
if (cachedResult) {
58-
return cachedResult;
59-
}
55+
// const cacheKey = `posts:stats:${userId}`;
56+
// const cachedResult = await cache.get(cacheKey);
57+
// if (cachedResult) {
58+
// return cachedResult;
59+
// }
6060

6161
const postsStatistics = await this.postRepo.getYesterdayAndTodayViewLikeStats(userId);
6262

@@ -68,10 +68,10 @@ export class PostService {
6868
lastUpdatedDate: postsStatistics.last_updated_date,
6969
};
7070

71-
// 결과가 빈 값이 아니라면 캐시에 저장 (5분 TTL)
72-
if (transformedStatistics.totalViews > 0) {
73-
await cache.set(cacheKey, transformedStatistics, 300);
74-
}
71+
// // 결과가 빈 값이 아니라면 캐시에 저장 (5분 TTL)
72+
// if (transformedStatistics.totalViews > 0) {
73+
// await cache.set(cacheKey, transformedStatistics, 300);
74+
// }
7575

7676
return transformedStatistics;
7777
} catch (error) {

0 commit comments

Comments
 (0)