fix(common): 이미지 캐시 디렉터리를 분리한다

This commit is contained in:
2026-06-05 20:53:20 +09:00
parent 9de4493e89
commit 7f307346f3
2 changed files with 51 additions and 1 deletions

View File

@@ -7,6 +7,9 @@ import okhttp3.OkHttpClient
import java.io.File
object ImageLoaderProvider {
const val LEGACY_OKHTTP_IMAGE_CACHE_DIRECTORY_NAME = "image_cache"
const val COIL_IMAGE_CACHE_DIRECTORY_NAME = "coil_image_cache"
lateinit var imageLoader: ImageLoader
private set
@@ -14,9 +17,10 @@ object ImageLoaderProvider {
get() = ::imageLoader.isInitialized
fun init(context: Context) {
val cacheSize = 250L * 1024L * 1024L // 250 MB
File(context.cacheDir, LEGACY_OKHTTP_IMAGE_CACHE_DIRECTORY_NAME).deleteRecursively()
val cacheDirectory = File(
context.cacheDir,
"image_cache"
COIL_IMAGE_CACHE_DIRECTORY_NAME
).apply { mkdirs() }
val cache = Cache(cacheDirectory, cacheSize)

View File

@@ -0,0 +1,46 @@
package kr.co.vividnext.sodalive.common
import android.app.Application
import androidx.test.core.app.ApplicationProvider
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import java.io.File
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], application = Application::class)
class ImageLoaderProviderTest {
@Test
fun `image loader cache directory does not reuse legacy okhttp image cache`() {
assertNotEquals(
ImageLoaderProvider.LEGACY_OKHTTP_IMAGE_CACHE_DIRECTORY_NAME,
ImageLoaderProvider.COIL_IMAGE_CACHE_DIRECTORY_NAME
)
}
@Test
fun `image loader init deletes legacy cache and creates new cache directory`() {
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
val legacyCacheDirectory = File(
context.cacheDir,
ImageLoaderProvider.LEGACY_OKHTTP_IMAGE_CACHE_DIRECTORY_NAME
)
val newCacheDirectory = File(
context.cacheDir,
ImageLoaderProvider.COIL_IMAGE_CACHE_DIRECTORY_NAME
)
legacyCacheDirectory.mkdirs()
File(legacyCacheDirectory, "journal").writeText("libcore.io.DiskLruCache\n1\n2\n")
newCacheDirectory.deleteRecursively()
ImageLoaderProvider.init(context)
assertFalse(legacyCacheDirectory.exists())
assertTrue(newCacheDirectory.exists())
}
}