# `Nebulex.Adapter.Observable`
[🔗](https://github.com/elixir-nebulex/nebulex/blob/v3.0.3/lib/nebulex/adapter/observable.ex#L1)

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 {: .info}
>
> 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.

# `adapter_meta`

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

Proxy type to the adapter meta

# `filter`

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

Proxy type to a cache event filter

# `listener`

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

Proxy type to a cache event listener

# `metadata`

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

Proxy type to a cache event metadata

# `opts`

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

Proxy type to the cache options

# `register_event_listener`

```elixir
@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 `c:Nebulex.Cache.register_event_listener/2`.

# `unregister_event_listener`

```elixir
@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 `c:Nebulex.Cache.unregister_event_listener/2`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
