Skip to content
Snippets Groups Projects
Unverified Commit 7d415833 authored by Matthias Urhahn's avatar Matthias Urhahn Committed by GitHub
Browse files

Fix app config caching (DEV) (#2997)


* If the server gives us a max-age=0, default to 300s.

* Fix lints.

Co-authored-by: default avatarharambasicluka <64483219+harambasicluka@users.noreply.github.com>
parent d8a4226f
No related branches found
No related tags found
No related merge requests found
......@@ -79,7 +79,15 @@ class AppConfigServer @Inject constructor(
val cacheControl = CacheControl.parse(headers)
val maxCacheAge = Duration.standardSeconds(cacheControl.maxAgeSeconds.toLong())
val maxCacheAge = cacheControl.maxAgeSeconds.let {
if (it == 0) {
// Server currently returns `Cache-Control max-age=0, no-cache, no-store` which breaks our caching
Timber.tag(TAG).w("Server returned max-age=0: %s", cacheControl)
Duration.standardSeconds(300)
} else {
Duration.standardSeconds(it.toLong())
}
}
return InternalConfigData(
rawData = rawConfig,
......
......@@ -229,6 +229,35 @@ class AppConfigServerTest : BaseIOTest() {
)
}
@Test
fun `cache control with max-age=0 defaults to 300 seconds`() = runBlockingTest {
coEvery { api.getApplicationConfiguration() } returns Response.success(
APPCONFIG_BUNDLE.toResponseBody(),
Headers.headersOf(
"Date",
"Tue, 03 Nov 2020 08:46:03 GMT",
"ETag",
"I am an ETag :)!",
"Cache-Control",
"max-age=0, no-cache, no-store"
)
)
val downloadServer = createInstance()
val configDownload = downloadServer.downloadAppConfig()
configDownload shouldBe InternalConfigData(
rawData = APPCONFIG_RAW,
serverTime = Instant.parse("2020-11-03T08:46:03.000Z"),
localOffset = Duration(
Instant.parse("2020-11-03T08:46:03.000Z"),
Instant.ofEpochMilli(123456789)
),
etag = "I am an ETag :)!",
cacheValidity = Duration.standardSeconds(300)
)
}
companion object {
private val APPCONFIG_BUNDLE =
(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment