Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache freshness is not updated on successful network fetch #1338

Open
mariolourobert opened this issue Jun 6, 2024 · 0 comments
Open

Cache freshness is not updated on successful network fetch #1338

mariolourobert opened this issue Jun 6, 2024 · 0 comments
Labels

Comments

@mariolourobert
Copy link

On Zipline v1.10.1

Running the code below, it looks like the cache freshness is not updated even through successful fetches, until the Kotlin/JS code exposed by the server is actually updated.

To reproduce:

  • Run the launchZipline function below multiple times with a valid network
  • Observe the log freshAtEpochMs that is triggered in the FreshnessChecker.isFresh callback
  • The freshAtEpochMs is always the same, even after multiple successful fetches -> ISSUE
  • Update the Kotlin/JS code on the server
  • Re-trigger the launchZipline function
  • The freshAtEpochMs is updated
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
            }
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants