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
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
_ ->
initial_cache
end
count
@ -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
cached_values
[] ->
nil
end
end
defp cache_period do

Loading…
Cancel
Save