problem: caching is not verified

This commit is contained in:
Igor Artamonov
2019-12-30 00:21:54 -05:00
parent d1585287b0
commit 38bb9a0fa5
3 changed files with 88 additions and 0 deletions

View File

@@ -108,6 +108,10 @@ class NativeCall(
fun fetch(ctx: CallContext<ParsedCallDetails>): Mono<CallContext<ByteArray>> {
return fetchFromCache(ctx)
.onErrorResume { t ->
log.warn("Failed to read from cache", t);
Mono.empty()
}
.switchIfEmpty(
Mono.just(ctx).flatMap(this::executeOnRemote)
)

View File

@@ -27,6 +27,7 @@ import io.infinitape.etherjar.hex.HexQuantity
import io.infinitape.etherjar.rpc.json.BlockJson
import io.infinitape.etherjar.rpc.json.ResponseJson
import io.infinitape.etherjar.rpc.json.TransactionRefJson
import org.slf4j.LoggerFactory
import reactor.core.publisher.Mono
import java.util.function.Function
@@ -37,6 +38,8 @@ open class CachingEthereumApi(
): EthereumApi(objectMapper) {
companion object {
private val log = LoggerFactory.getLogger(CachingEthereumApi::class.java)
@JvmStatic
fun empty(): CachingEthereumApi {
return CachingEthereumApi(ObjectMapper(), EmptyReader(), EmptyEthereumHead())
@@ -55,6 +58,10 @@ open class CachingEthereumApi(
.map { BlockHash.from(it as String) }
.flatMap(cache::read)
.map(toJson(id))
.onErrorResume { t ->
log.warn("Error during read from cache", t)
Mono.empty()
}
else Mono.empty()
else ->
Mono.empty()