Skip to content

Commit

Permalink
Try to reload cache if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmanzanera committed Jan 10, 2024
1 parent d61e958 commit 867825a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/archethic_fas/quotes/cache.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 867825a

Please sign in to comment.