View Source Nebulex.Adapter.Stats behaviour (Nebulex v2.5.2)
Specifies the stats API required from adapters.
Each adapter is responsible for providing support for stats by implementing this behaviour. However, this module brings with a default implementation using [Erlang counters][https://erlang.org/doc/man/counters.html], with all callbacks overridable, which is supported by the built-in adapters.
See Nebulex.Adapters.Local
for more information about how this can be used
from the adapter, and also Nebulex Telemetry Guide to learn
how to use the Cache with Telemetry.
Link to this section Summary
Callbacks
Returns Nebulex.Stats.t()
with the current stats values.
Functions
Increments the counter
's stat_name
by the given incr
value.
Initializes the Erlang's counter to be used by the adapter. See the module documentation for more information about the stats default implementation.
Link to this section Callbacks
@callback stats(Nebulex.Adapter.adapter_meta()) :: Nebulex.Stats.t() | nil
Returns Nebulex.Stats.t()
with the current stats values.
If the stats are disabled for the cache, then nil
is returned.
The adapter may also include additional custom measurements, as well as metadata.
Link to this section Functions
@spec incr(:counters.counters_ref() | nil, atom(), integer()) :: :ok
Increments the counter
's stat_name
by the given incr
value.
examples
Examples
Nebulex.Adapter.Stats.incr(stats_counter, :hits)
Nebulex.Adapter.Stats.incr(stats_counter, :writes, 10)
NOTE: This function is usually called by the adapter in case it uses the default implementation; the adapter should feed
Nebulex.Stats.t()
counters.
See adapters documentation for more information about stats implementation.
@spec init(Keyword.t()) :: :counters.counters_ref() | nil
Initializes the Erlang's counter to be used by the adapter. See the module documentation for more information about the stats default implementation.
Returns nil
is the option :stats
is set to false
or it is not set at
all; the stats will be skipped.
example
Example
Nebulex.Adapter.Stats.init(opts)
NOTE: This function is usually called by the adapter in case it uses the default implementation; the adapter should feed
Nebulex.Stats.t()
counters.
See adapters documentation for more information about stats implementation.