Nebulex.Adapter.Observable behaviour (Nebulex v3.0.0-rc.1)

View Source

Specifies the adapter Observable API.

Maintains a registry of listeners and invokes them to handle cache events.

Default implementation

Nebulex provides a default implementation for the Nebulex.Adapter.Observable behaviour, which uses a Telemetry handler to listen to cache command completion events, builds the corresponding cache entry event, and applies the provided filter and listener.

Listeners should be implemented with care. In particular, it is important to consider their impact on performance and latency.

Listeners:

  • are fired after the entry is mutated in the cache.
  • block the calling process until the listener returns since the listener is evaluated synchronously.

Function Captures

Due to how anonymous functions are implemented in the Erlang VM, it is best to use function captures (&Mod.fun/1) as event listeners and filters to achieve the best performance. In other words, avoid using literal anonymous functions (fn ... -> ... end) or local function captures (&handle_event/1) as event listeners and filters.

Summary

Types

Proxy type to the adapter meta

Proxy type to a cache event filter

Proxy type to a cache event listener

Proxy type to a cache event metadata

Proxy type to the cache options

Types

adapter_meta()

@type adapter_meta() :: Nebulex.Adapter.adapter_meta()

Proxy type to the adapter meta

filter()

@type filter() :: Nebulex.Event.filter()

Proxy type to a cache event filter

listener()

@type listener() :: Nebulex.Event.listener()

Proxy type to a cache event listener

metadata()

@type metadata() :: Nebulex.Event.metadata()

Proxy type to a cache event metadata

opts()

@type opts() :: Nebulex.Cache.opts()

Proxy type to the cache options

Callbacks

register_event_listener(adapter_meta, listener, filter, metadata, opts)

@callback register_event_listener(
  adapter_meta(),
  listener(),
  filter(),
  metadata(),
  opts()
) ::
  :ok | Nebulex.Cache.error_tuple()

Register a cache event listener.

Returns :ok if successful; {:error, reason} otherwise.

See Nebulex.Cache.register_event_listener/2.

unregister_event_listener(adapter_meta, id, opts)

@callback unregister_event_listener(adapter_meta(), id :: any(), opts()) ::
  :ok | Nebulex.Cache.error_tuple()

Un-register a cache event listener.

Returns :ok if successful; {:error, reason} otherwise.

See Nebulex.Cache.unregister_event_listener/2.