Mario Robert
06/05/2024, 3:29 PMjessewilson
06/05/2024, 8:20 PMjessewilson
06/05/2024, 8:21 PMloadOnce()
twice, with different FreshnessChecker
arguments on each callMario Robert
06/06/2024, 9:51 AMfreshAtEpochMs
param in the callback FreshnessChecker.isFresh
has always the same value until I update the Kotlin/JS code on the server 🤔 I thought the cache will be updated at each successful network fetch.
Please find the code below. I execute it at app startup. I observe in the logs that even if the network fetch succeeded, the next isFresh call (at next app startup) will be executed with a non-updated freshAtEpochMs value.
suspend fun launchZipline(dispatcher: CoroutineDispatcher): Zipline? {
val manifestUrl = "<http://10.0.2.2:8080/manifest.zipline.json>"
val ziplineCache = ZiplineCache(
applicationContext,
FileSystem.SYSTEM,
applicationContext.cacheDir.toOkioPath(),
10 * 1024 * 1024, // 10MB
)
val loader = ZiplineLoader(
dispatcher,
ManifestVerifier.NO_SIGNATURE_CHECKS,
OkHttpClient(),
).withCache(ziplineCache)
val cacheDuration = Duration.ofMinutes(1L)
val freshnessChecker = object : FreshnessChecker {
override fun isFresh(manifest: ZiplineManifest, freshAtEpochMs: Long): Boolean =
(System.currentTimeMillis() - freshAtEpochMs < cacheDuration.toMillis())
.also {
Log.d("Zipline", "freshAtEpochMs: $freshAtEpochMs")
Log.d("Zipline", "Is the cache fresh? $it")
}
}
return when (
val result = loader.loadOnce(AppZiplineInterfaceName, freshnessChecker, manifestUrl)
) {
is LoadResult.Success -> {
Log.d("Zipline", "Zipline loaded freshAtEpochMs: ${result.freshAtEpochMs}")
result.zipline
}
is LoadResult.Failure -> {
Log.e("Zipline", "Failed to load Zipline \n ${result.exception.message}")
null
}
}
}
Mario Robert
06/06/2024, 9:52 AMjessewilson
06/06/2024, 9:55 AMjessewilson
06/06/2024, 9:56 AMMario Robert
06/06/2024, 9:56 AMMario Robert
06/06/2024, 2:14 PM