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

Specifies the minimal API required from adapters.

# `adapter_meta`

```elixir
@type adapter_meta() :: %{optional(atom()) =&gt; any()}
```

The metadata returned by the adapter `c:init/1`.

It must be a map and Nebulex itself will always inject
the following keys into the meta:

  * `:cache` - The defined cache module.
  * `:name` - The name of the cache supervisor process.
  * `:pid` - The PID returned by the child spec returned in `c:init/1`.
  * `:adapter` - The defined cache adapter.
  * `:telemetry` - Whether Telemetry is enabled or not.
  * `:telemetry_prefix` – The Telemetry prefix.

# `nbx_error`

```elixir
@type nbx_error() :: Nebulex.Error.t() | Nebulex.KeyError.t()
```

Nebulex wrappable error types

# `t`

```elixir
@type t() :: module()
```

Adapter

# `__before_compile__`
*optional* 

```elixir
@macrocallback __before_compile__(env :: Macro.Env.t()) :: Macro.t()
```

The callback invoked in case the adapter needs to inject code.

# `init`

```elixir
@callback init(config :: keyword()) :: {:ok, :supervisor.child_spec(), adapter_meta()}
```

Initializes the adapter supervision tree by returning the children
and adapter metadata.

# `defcommand`
*macro* 

Builds up a public wrapper function for invoking an adapter command.

**NOTE:** Internal purposes only.

# `defcommandp`
*macro* 

Builds up a private wrapper function for invoking an adapter command.

**NOTE:** Internal purposes only.

# `handle_command_response`

```elixir
@spec handle_command_response(ok | {:error, any()}) :: ok | {:error, nbx_error()}
when ok: :ok | {:ok, any()}
```

Helper function for handling a Nebulex command response.

## Examples

    iex> Nebulex.Adapter.handle_command_response({:ok, "ok"})
    {:ok, "ok"}

    iex> Nebulex.Adapter.handle_command_response(:ok)
    :ok

    iex> Nebulex.Adapter.handle_command_response(
    ...>   {:error, %Nebulex.Error{reason: :error}}
    ...> )
    {:error, %Nebulex.Error{reason: :error}}

    iex> Nebulex.Adapter.handle_command_response({:error, :error})
    {:error, %Nebulex.Error{reason: :error}}

    iex> Nebulex.Adapter.handle_command_response({:error, %RuntimeError{}})
    {:error, %Nebulex.Error{reason: %RuntimeError{}}}

# `lookup_meta`

```elixir
@spec lookup_meta(atom() | pid()) :: adapter_meta()
```

Returns the adapter metadata from its `c:init/1` callback.

It expects a process name of the cache. The name is either
an atom or a PID. For a given cache, you often want to call
this function based on the dynamic cache:

    Nebulex.Adapter.lookup_meta(cache.get_dynamic_cache())

# `run_command`

```elixir
@spec run_command(adapter_meta(), atom(), [any()], keyword()) :: any()
```

Convenience function for invoking the adapter running a command.

**NOTE:** Internal purposes only.

---

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