Skip to content

Commit

Permalink
Move the ZiplineCache out of Android's cache dir (#1612)
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse authored Oct 18, 2023
1 parent 0edbe3d commit ff7c0f1
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package app.cash.redwood.treehouse

import android.content.Context
import android.content.Context.MODE_PRIVATE
import android.util.Log
import app.cash.zipline.loader.ZiplineCache
import okio.FileSystem
Expand All @@ -32,10 +33,19 @@ internal class AndroidTreehousePlatform(
Log.w("Zipline", message, throwable)
}

/**
* Note that we don't put the ZiplineCache in Android's cacheDir.
*
* We don't have any control over when files are evicted from that directory, and we've observed
* crashes because the cache's SQLite database file was evicted ('SQLITE_READONLY_DBMOVED') while
* the app was running.
*
* This is safe because ZiplineCache automatically prunes itself to [maxSizeInBytes].
*/
override fun newCache(name: String, maxSizeInBytes: Long) = ZiplineCache(
context = context,
fileSystem = FileSystem.SYSTEM,
directory = context.cacheDir.toOkioPath() / name,
directory = context.getDir(name, MODE_PRIVATE).toOkioPath(),
maxSizeInBytes = maxSizeInBytes,
)
}

0 comments on commit ff7c0f1

Please sign in to comment.