perf(app): Kingfisher 캐시 상한 구성 및 메모리 정리 훅 추가

왜: 디코딩된 비트맵의 과도한 보존으로 피크 메모리 증가. 전역
상한/만료 설정과 시스템 이벤트 연동으로 안정화 필요.

무엇(`SodaLiveApp.swift`):
- `ImageCache.default` 구성
  - 메모리: `totalCostLimit=120MB`, `countLimit=200`, `expiration=300s`
  - 디스크: `sizeLimit=500MB`
- 훅 추가
  - `didReceiveMemoryWarning` → `clearMemoryCache()`
  - `didEnterBackground` → `cleanExpiredMemoryCache()`

검증: 앱 기동/백그라운드/포어그라운드 전환 플로우 정상, 빌드 성공.
This commit is contained in:
Yu Sung
2025-10-23 14:49:04 +09:00
parent 1fc608a9af
commit 425a767927

View File

@@ -6,6 +6,7 @@
// //
import SwiftUI import SwiftUI
import Kingfisher
import FBSDKCoreKit import FBSDKCoreKit
import AppsFlyerLib import AppsFlyerLib
@@ -19,11 +20,34 @@ struct SodaLiveApp: App {
@StateObject var canPgPaymentViewModel = CanPgPaymentViewModel() @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 { var body: some Scene {
WindowGroup { WindowGroup {
ContentView(canPgPaymentViewModel: canPgPaymentViewModel) ContentView(canPgPaymentViewModel: canPgPaymentViewModel)
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in .onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in
CreatorCommunityMediaPlayerManager.shared.pauseContent() 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 .onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in
UIApplication.shared.applicationIconBadgeNumber = 0 UIApplication.shared.applicationIconBadgeNumber = 0