Razvan
01/20/2021, 8:13 PMfun main() {
val storage = ReadWriteCache.Disk()
val withCachedContent = TrafficFilters.ServeCachedFrom(storage).then { Response(OK).body("hello world: ${LocalDateTime.now()}") }
val aRequest = Request(Method.GET, "<http://localhost:8000/>")
println("--- FIRST ----")
println(withCachedContent(aRequest))
Thread.sleep(1000)
println("--- SECOND ----")
println(withCachedContent(aRequest))
}
I expected both output to show the same time and not different ones....val cache = ReadWriteCache.Memory()
cache[request] = response
does that mean that ServeCachedFrom
does not automatically cache requests that does not yet cached ?dave
01/20/2021, 8:35 PMfun `disk cache!`(dir: String): Http4kServer {
val cache = ReadWriteCache.Disk(dir)
return ProxyHost(Https)
.then(RecordTo(cache))
.then(ServeCachedFrom(cache))
.then(ReportHttpTransaction { println(it.request.uri) })
.then(JavaHttpClient())
.asServer(KtorCIO())
.start()
}
Razvan
01/21/2021, 8:06 AMdave
01/21/2021, 8:10 AMRazvan
01/21/2021, 8:23 AM