diff --git a/SodaLive/Sources/App/SodaLiveApp.swift b/SodaLive/Sources/App/SodaLiveApp.swift index 9ff2831..9376485 100644 --- a/SodaLive/Sources/App/SodaLiveApp.swift +++ b/SodaLive/Sources/App/SodaLiveApp.swift @@ -6,6 +6,7 @@ // import SwiftUI +import Kingfisher import FBSDKCoreKit import AppsFlyerLib @@ -19,11 +20,34 @@ struct SodaLiveApp: App { @StateObject var canPgPaymentViewModel = CanPgPaymentViewModel() + init() { + configureImageCache() + } + + private func configureImageCache() { + // Kingfisher 전역 캐시 상한 설정 + let cache = ImageCache.default + // 총 메모리 비용(바이트). 이미지 1장이 수 MB 수준이므로 80~150MB 범위 권장 + cache.memoryStorage.config.totalCostLimit = 120 * 1024 * 1024 + // 객체 개수 제한(옵션) + cache.memoryStorage.config.countLimit = 200 + // 메모리 만료 정책(옵션) + cache.memoryStorage.config.expiration = .seconds(300) + // 디스크 캐시 용량 제한(옵션) + cache.diskStorage.config.sizeLimit = 500 * 1024 * 1024 + } + var body: some Scene { WindowGroup { ContentView(canPgPaymentViewModel: canPgPaymentViewModel) .onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in CreatorCommunityMediaPlayerManager.shared.pauseContent() + // 백그라운드 전환 시 메모리 캐시 정리 + ImageCache.default.cleanExpiredMemoryCache() + } + .onReceive(NotificationCenter.default.publisher(for: UIApplication.didReceiveMemoryWarningNotification)) { _ in + // 메모리 경고 수신 시 캐시 즉시 해제 + ImageCache.default.clearMemoryCache() } .onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in UIApplication.shared.applicationIconBadgeNumber = 0