update cache if cache is nil

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

@ -29,14 +29,16 @@ defmodule Explorer.Chain.BlockCountCache do
end
def count do
initial_cache = {_count, old_current_time} = cached_values()
initial_cache = cached_values()
{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()
cached_values()
else
_ ->
initial_cache
end
@ -58,9 +60,13 @@ defmodule Explorer.Chain.BlockCountCache do
end
defp cached_values do
[{_, cached_values}] = :ets.lookup(@tab, @key)
case :ets.lookup(@tab, @key) do
[{_, cached_values}] ->
cached_values
[] ->
nil
end
end
defp cache_period do

Loading…
Cancel
Save