Base64ImageCache LruCache sizeOf() 오버라이드로 메모리 초과 방지
- maxMemory/8(KB 단위)로 설정된 LruCache가 항목 개수로 동작하던 문제 수정 - String 메모리 점유량(KB)을 계산하는 sizeOf() 구현 추가
This commit is contained in:
@@ -27,8 +27,13 @@ object Base64ImageCache {
|
||||
private val maxMemory = (Runtime.getRuntime().maxMemory() / 1024).toInt()
|
||||
private val cacheSize = maxMemory / 8
|
||||
|
||||
// L1 Cache: Memory (Key: Image URL, Value: Base64 Data String)
|
||||
private val lru: LruCache<String, String> = LruCache(cacheSize)
|
||||
// L1 Cache: Memory (Key: Image URL, Value: Base64 Data String, 단위: KB)
|
||||
private val lru: LruCache<String, String> = object : LruCache<String, String>(cacheSize) {
|
||||
override fun sizeOf(key: String, value: String): Int {
|
||||
// Char당 2바이트 기준 KB 단위로 환산 (최소 1KB)
|
||||
return maxOf(1, (value.length * 2) / 1024)
|
||||
}
|
||||
}
|
||||
|
||||
// L2 Cache: File System
|
||||
private var cacheDir: File? = null
|
||||
|
||||
Reference in New Issue
Block a user