update cache if cache is nil

pull/1876/head
saneery 6 years ago
parent fbf07820d3
commit 7e5e3536d0
  1. 16
      apps/explorer/lib/explorer/chain/block_count_cache.ex

@ -29,15 +29,17 @@ defmodule Explorer.Chain.BlockCountCache do
end end
def count do def count do
initial_cache = {_count, old_current_time} = cached_values() initial_cache = cached_values()
{count, _current_time} = {count, _current_time} =
if current_time() - old_current_time > cache_period() do with {_count, old_current_time} <- initial_cache,
true <- current_time() - old_current_time > cache_period() do
update_cache() update_cache()
cached_values() cached_values()
else else
initial_cache _ ->
initial_cache
end end
count count
@ -58,9 +60,13 @@ defmodule Explorer.Chain.BlockCountCache do
end end
defp cached_values do defp cached_values do
[{_, cached_values}] = :ets.lookup(@tab, @key) case :ets.lookup(@tab, @key) do
[{_, cached_values}] ->
cached_values
cached_values [] ->
nil
end
end end
defp cache_period do defp cache_period do

Loading…
Cancel
Save