|
|
|
@ -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 |
|
|
|
|