From 867825afaa934fa276669d516b739bb55993ae16 Mon Sep 17 00:00:00 2001 From: Samuel Manzanera Date: Wed, 10 Jan 2024 18:50:44 +0100 Subject: [PATCH] Try to reload cache if not found --- lib/archethic_fas/quotes/cache.ex | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/archethic_fas/quotes/cache.ex b/lib/archethic_fas/quotes/cache.ex index e4a9869..2f664c9 100644 --- a/lib/archethic_fas/quotes/cache.ex +++ b/lib/archethic_fas/quotes/cache.ex @@ -20,8 +20,18 @@ defmodule ArchethicFAS.Quotes.Cache do @spec get_latest() :: {:ok, %{Currency.t() => float()}} | {:error, String.t()} def get_latest() do case :ets.lookup(@table, :latest) do - [{:latest, value}] -> value - [] -> {:error, "Value not cached yet"} + [{:latest, value}] -> + value + + [] -> + case hydrate() do + {:ok, value} -> + value + + {:error, reason} -> + Logger.warning("Hydrating failed: #{inspect(reason)}") + {:error, "Value not cached yet"} + end end end