Nebulex.Adapter.Stats behaviour (Nebulex v2.0.0) View Source

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

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.

Callbacks

Returns Nebulex.Stats.t() with the current stats values.

Link to this section Functions

Link to this function

incr(counter, stat_name, incr \\ 1)

View Source

Specs

incr(:counters.counters_ref() | nil, atom(), integer()) :: :ok

Increments the counter's stat_name by the given incr value.

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.

Specs

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

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.

Link to this section Callbacks

Specs

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.

See Nebulex.Cache.stats/0.