Thank you, Sir!
With your guide, I found the possible source of definition of get_count here:
link: blockscout/apps/explorer/lib/explorer/chain/map_cache.ex at ac3d00acd2210fe70798da83730c39a01d0f5b43 · blockscout/blockscout · GitHub
# apps/explorer/lib/explorer/chain/map_cache.ex
defmodule Explorer.Chain.MapCache do
@moduledoc """
Behaviour for a map-like cache of elements.
A macro based on `ConCache` is provided as well, at its minimum it can be used as;
use Explorer.Chain.MapCache,
name: :name,
keys: [:fst, :snd]
Note: `keys` can also be set singularly with the option `key`, e.g.:
use Explorer.Chain.MapCache,
name: :cache,
key: :fst,
key: :snd
"""
@impl MapCache
def get(key) do
case ConCache.get(cache_name(), key) do
nil ->
case handle_fallback(key) do
{:update, new_value} ->
update(key, new_value)
new_value
{:return, new_value} ->
new_value
end
value ->
value
end
end
then in this file:
# apps/explorer/lib/explorer/chain/cache/block.ex
# :fst is :count now
use Explorer.Chain.MapCache,
name: :block_count,
**key: :count,**
key: :async_task,
global_ttl: Application.get_env(:explorer, __MODULE__)[:global_ttl],
ttl_check_interval: :timer.seconds(1),
callback: &async_task_on_deletion(&1)
I have another question.
Why does __MODULE__ in the code above represent Explorer.Chain.MapCache module but not the current module, i, e. Explorer.Chain.Cache.Block?
Or I misunderstood what is the usage of __MODULE__ used here. Could you explain the metaprogramming a bit more for me? Especially, how is the get_count defined here?
Thank you so much.