View Source Cachex.Router.Mod (Cachex v4.0.1)

Routing implementation based on basic hashing.

This router provides the simplest (and quickest!) implementation for clusters of a static size. Provided keys are hashed and routed to a node via the modulo operation. Please note that the hash algorithm should not be relied upon and is not considered part of the public API.

The initialization of this router accepts a :nodes option which enables the user to define the nodes to route amongst. If this is not provided the router will default to detecting a cluster via Node.self/0 and Node.list/1.

Summary

Functions

Initialize a modulo routing state for a cache.

Retrieve the list of nodes from a modulo routing state.

Route a key to a node in a modulo routing state.

Functions

Link to this function

init(cache, options \\ [])

View Source
@spec init(cache :: Cachex.t(), options :: Keyword.t()) :: [atom()]

Initialize a modulo routing state for a cache.

Options

  • :nodes

    The :nodes option allows a user to provide a list of nodes to treat as a cluster. If this is not provided, the cluster will be inferred by using Node.self/0 and Node.list/1.

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

Retrieve the list of nodes from a modulo routing state.

@spec route(nodes :: [atom()], key :: any()) :: atom()

Route a key to a node in a modulo routing state.