View Source ProcessHub.Service.Storage (ProcessHub v0.6.0)

Local storage service. Provides API functions for managing local storage used by ProcessHub for three concerns:

When a registry backend is opened it registers itself with this module via register_backend/3. From then on, calls to the public API that target a registry table (the hub_id atom) are dispatched through the configured backend module. Misc and hook storage (passed by tid) bypass the dispatcher and use ETS directly.

The public function signatures and return values are unchanged from prior releases.

Summary

Functions

Deletes all objects from the storage table.

Returns a boolean indicating whether the key exists in local storage.

Exports all objects from the storage table.

Folds over all objects in the storage table with a function.

Returns the value for the key in local storage.

Inserts the key and value into local storage.

Matches the given expression against the storage table.

Registers {module, ref} as the registry backend for hub_id.

Returns {module, ref} for the registered registry backend, or nil if hub_id has no registered backend.

Removes an entry from the storage.

Removes the registered backend for hub_id. Called by the coordinator at shutdown.

Updates the value for the key in local storage.

Types

@type table_id() :: atom() | :ets.tid()

Functions

@spec clear_all(table_id()) :: boolean() | :ok

Deletes all objects from the storage table.

Never use in custom code. Should only be used for testing purposes.

@spec exists?(table_id(), term()) :: boolean()

Returns a boolean indicating whether the key exists in local storage.

@spec export_all(table_id()) :: [{atom() | binary(), term(), pos_integer() | nil}]

Exports all objects from the storage table.

@spec foldl(table_id(), acc, (term(), acc -> acc)) :: acc when acc: term()

Folds over all objects in the storage table with a function.

More memory efficient than export_all + filter for large tables as it doesn't create an intermediate copy of the entire table.

@spec get(table_id(), term()) :: term()

Returns the value for the key in local storage.

If the key does not exist, nil is returned; otherwise, the value is returned in the format of a tuple: {key, value, ttl}.

Link to this function

insert(table, key, value, opts \\ [])

View Source
@spec insert(table_id(), term(), term(), keyword() | nil) :: boolean() | :ok

Inserts the key and value into local storage.

Available options:

  • ttl: The time to live for the key in milliseconds.
Link to this function

match(table, match_expr)

View Source
@spec match(table_id(), term()) :: term()

Matches the given expression against the storage table.

The match_expr is a tuple that specifies the pattern.

Link to this function

register_backend(hub_id, module, ref)

View Source
@spec register_backend(atom(), module(), term()) :: :ok

Registers {module, ref} as the registry backend for hub_id.

After registration, public API calls passing hub_id (an atom) are dispatched through module. Called by the coordinator at startup.

Link to this function

registered_backend(hub_id)

View Source
@spec registered_backend(atom()) :: {module(), term()} | nil

Returns {module, ref} for the registered registry backend, or nil if hub_id has no registered backend.

@spec remove(table_id(), term()) :: boolean() | :ok

Removes an entry from the storage.

Link to this function

unregister_backend(hub_id)

View Source
@spec unregister_backend(atom()) :: :ok

Removes the registered backend for hub_id. Called by the coordinator at shutdown.

Link to this function

update(table, key, func)

View Source
@spec update(table_id(), term(), function()) :: boolean()

Updates the value for the key in local storage.

The func function is expected to take the current value as an argument and return the new value.

If the key does not exist, the current value is nil.