Cachex v3.2.0 Cachex.Services.Overseer View Source

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

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.

Link to this function

known?(name)

View Source
known?(atom()) :: true | false

Determines whether a cache is known by the Overseer.

Link to this function

register(name, cache)

View Source
register(atom(), Supervisor.Spec.cache()) :: true

Registers a cache record against a name.

Retrieves a cache record, or nil if none exists.

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.

Determines whether the Overseer has been started.

Link to this function

transaction(name, fun)

View Source
transaction(atom(), (() -> any())) :: any()

Carries out a transaction against the state table.

Link to this function

unregister(name)

View Source
unregister(atom()) :: true

Unregisters a cache record against a name.

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.