View Source Cachex.Hook behaviour (Cachex v4.0.2)
Module controlling hook behaviour definitions.
This module defines the hook implementations for Cachex, allowing the user to add hooks into the command execution. This means that users can build plugin style listeners in order to do things like logging. Hooks can be registered to execute either before or after the Cachex command, and can be blocking as needed.
Summary
Callbacks
Returns the actions this hook is expected to listen on.
Returns whether this hook is asynchronous or not.
Handles a cache notification.
Returns the timeout for all calls to this hook.
Returns the type of this hook.
Functions
Concatenates all hooks in a cache.
Locates a hook module for a cache.
Retrieve all known types of hook.
Callbacks
@callback actions() :: :all | [atom()]
Returns the actions this hook is expected to listen on.
This will default to an empty list, to force the developer to opt into the
actions they receive notifications for. If all actions should be received,
you can use the :all
atom to receive everything.
@callback async?() :: boolean()
Returns whether this hook is asynchronous or not.
@callback handle_notify( action :: {action :: atom(), args :: list()}, result :: {status :: atom(), value :: any()}, state :: any() ) :: {:ok, any()}
Handles a cache notification.
The first argument is the action being taken along with arguments, with the second argument being the results of the action (this can be nil for hooks) which fire before the action is executed.
@callback timeout() :: nil | integer()
Returns the timeout for all calls to this hook.
This will be applied to hooks regardless of whether they're synchronous or not; a behaviour change which shipped in v3.0 initially.
@callback type() :: :pre | :post | :service
Returns the type of this hook.
This should return :post
to fire after a cache action has occurred, and
return :pre
if it should fire before the action occurs. The :quiet
type
is for hooks which don't listen to any broadcasts.
Functions
@spec concat(Cachex.t() | Cachex.Spec.hooks()) :: [Cachex.Spec.hook()]
Concatenates all hooks in a cache.
@spec locate(Cachex.t() | Cachex.Spec.hooks(), atom(), atom()) :: Cachex.Spec.hook() | nil
Locates a hook module for a cache.
Retrieve all known types of hook.