View Source Cachex.Services.Overseer (Cachex v3.6.0)

Service module overseeing the persistence of cache records.

This module controls the state of caches being handled by Cachex. This was originally part of an experiment to see if it was viable to remove a process which backed each cache to avoid bottlenecking scenarios and grant the develop finer control over their concurrency.

The result was much higher throughput with better flexibility, and so we kept this new design. Cache states are stored in a single ETS table backing this module and all cache calls will be routed through here first to ensure their state is up to date.

Link to this section Summary

Functions

Ensures a cache from a name or record.

Determines whether a cache is known by the Overseer.

Registers a cache record against a name.

Retrieves a cache record, or nil if none exists.

Creates a new Overseer service tree.

Determines whether the Overseer has been started.

Carries out a transaction against the state table.

Unregisters a cache record against a name.

Updates a cache record against a name.

Link to this section Functions

@spec ensure(atom() | Supervisor.Spec.cache()) :: Supervisor.Spec.cache() | nil

Ensures a cache from a name or record.

Ensuring a cache will map the provided argument to a cache record if available, otherwise a nil value.

@spec known?(atom()) :: true | false

Determines whether a cache is known by the Overseer.

@spec register(atom(), Supervisor.Spec.cache()) :: true

Registers a cache record against a name.

@spec retrieve(atom()) :: Supervisor.Spec.cache() | nil

Retrieves a cache record, or nil if none exists.

@spec start_link() :: Supervisor.on_start()

Creates a new Overseer service tree.

This will start a basic Agent for transactional changes, as well as the main ETS table backing this service.

@spec started?() :: boolean()

Determines whether the Overseer has been started.

@spec transaction(atom(), (() -> any())) :: any()

Carries out a transaction against the state table.

@spec unregister(atom()) :: true

Unregisters a cache record against a name.

@spec update(
  atom(),
  Supervisor.Spec.cache() | (Supervisor.Spec.cache() -> Supervisor.Spec.cache())
) :: Supervisor.Spec.cache()

Updates a cache record against a name.

This is atomic and happens inside a transaction to ensure that we don't get out of sync. Hooks are notified of the change, and the new state is returned.