Tezex.Rpc.EntrypointCache (tezex v6.0.0)

Copy Markdown View Source

Cache for the results of Tezex.Rpc.entrypoints/2 and Tezex.Rpc.entrypoint/3.

The process only owns a named public ETS table. Callers read and write the table directly, so lookups never go through the process.

Keys:

  • {endpoint, chain_id, address} for the entrypoint list of a contract
  • {endpoint, chain_id, address, name} for the type of one entrypoint

The endpoint is part of the key so that two networks never share entries. A contract's code can't change once it is deployed, so entries never expire. Only {:ok, _} results are stored. Once the table uses 32 MiB, storing one more entry empties it first.

Summary

Functions

Returns a specification to start this module under a supervisor.

Remove every entry.

Return the cached value for key as {:ok, value}. On a miss, call fun, store its result if it is {:ok, value}, and return it.

Return {:ok, value} if key is cached, :error otherwise.

Store value under key.

Types

key()

@type key() ::
  {endpoint :: binary(), chain_id :: binary(), address :: binary()}
  | {endpoint :: binary(), chain_id :: binary(), address :: binary(),
     name :: binary()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

@spec clear() :: :ok

Remove every entry.

fetch(key, fun)

@spec fetch(key(), (-> {:ok, value} | {:error, reason})) ::
  {:ok, value} | {:error, reason}
when value: term(), reason: term()

Return the cached value for key as {:ok, value}. On a miss, call fun, store its result if it is {:ok, value}, and return it.

lookup(key)

@spec lookup(key()) :: {:ok, term()} | :error

Return {:ok, value} if key is cached, :error otherwise.

put(key, value)

@spec put(key(), term()) :: :ok

Store value under key.