View Source Cachex.Router behaviour (Cachex v4.0.3)

Module controlling routing behaviour definitions.

This module defines the router implementations for Cachex, allowing the user to route commands between nodes in a cache cluster. This means that users can provide their own routing and rebalancing logic without having to depend on it being included in Cachex.

Summary

Callbacks

Create a child specification to back a routing state.

Initialize a routing state for a cache.

Retrieve the list of nodes from a routing state.

Route a key to a node in a routing state.

Functions

Retrieve all currently connected nodes (including this one).

Retrieve all routable nodes for a cache.

Dispatches a call to an appropriate execution environment.

Executes a previously dispatched action..

Callbacks

Link to this callback

children(cache, options)

View Source
@callback children(cache :: Cachex.t(), options :: Keyword.t()) :: Supervisor.child_spec()

Create a child specification to back a routing state.

@callback init(cache :: Cachex.t(), options :: Keyword.t()) :: any()

Initialize a routing state for a cache.

Please see all child implementations for supported options.

@callback nodes(state :: any()) :: [atom()]

Retrieve the list of nodes from a routing state.

@callback route(state :: any(), key :: any()) :: atom()

Route a key to a node in a routing state.

Functions

@spec connected() :: [atom()]

Retrieve all currently connected nodes (including this one).

@spec nodes(cache :: Cachex.t()) :: {:ok, [atom()]}

Retrieve all routable nodes for a cache.

Link to this macro

route(cache, call)

View Source (macro)

Dispatches a call to an appropriate execution environment.

This acts as a macro just to avoid the overhead of slicing up module names at runtime, when they can be guaranteed at compile time much more easily.

Link to this function

route(cache, module, call)

View Source
@spec route(Cachex.t(), atom(), {atom(), [any()]}) :: any()

Executes a previously dispatched action..