Cachex v3.2.0 Cachex.Services.Informant View Source

Parent module for all child hook definitions for a cache.

This module will control the supervision tree for all hooks that are associated with a cache. The links inside will create a tree to hold all hooks as children, as well as provide utility functions for new notifications being sent to child hooks for a cache.

Link to this section Summary

Functions

Broadcasts an action to all pre-hooks in a cache.

Broadcasts an action and result to all post-hooks in a cache.

Links all hooks in a cache to their running process.

Notifies a set of hooks of the passed in data.

Starts a new Informant service for a cache.

Link to this section Functions

Link to this function

broadcast(arg, action)

View Source
broadcast(Spec.cache(), tuple()) :: :ok

Broadcasts an action to all pre-hooks in a cache.

This will send a nil result, as the result does not yet exist.

Link to this function

broadcast(arg, action, result)

View Source
broadcast(Spec.cache(), tuple(), any()) :: :ok

Broadcasts an action and result to all post-hooks in a cache.

Link to this function

link(cache)

View Source
link(Spec.cache()) :: {:ok, Spec.cache()}

Links all hooks in a cache to their running process.

This is a required post-step as hooks are started independently and are not named in a deterministic way. It will look up all hooks using the Supervisor children and place them in a modified cache record.

Link to this function

notify(hooks, action, result)

View Source
notify([Spec.hook()], tuple(), any()) :: :ok

Notifies a set of hooks of the passed in data.

This is the underlying implementation for broadcast/2 and broadcast/3, but it's general purpose enough that it's exposed as part of the public API.

Link to this function

start_link(arg)

View Source
start_link(Spec.cache()) :: Supervisor.on_start()

Starts a new Informant service for a cache.

This will start a Supervisor to hold all hook processes as defined in the provided cache record. If no hooks are attached in the cache record, this will skip creating an unnecessary Supervisor process.