View Source ProcessHub.Service.Storage (ProcessHub v0.8.0)
Local storage service. Provides API functions for managing local storage used by ProcessHub for three concerns:
- Misc storage — strategy configs, runtime state. Always ETS.
- Hook storage — registered hook handlers. Always ETS.
- Process registry — child registrations. Routed through the
configured
ProcessHub.Service.Storage.Behaviourbackend (defaultProcessHub.Service.Storage.Ets).
Calls to the public API that target a registry table (the hub_id
atom) are dispatched through the backend of the running hub, read from
its stored ProcessHub.Hub. 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
Types
A plain ETS table, a hub id (its registry backend), or an opened
{module, ref} backend such as the declared list's.
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.
Folds over all objects as {key, value}, dropping the trailing TTL element
that entries inserted with a :ttl carry.
Returns the value for the key in local storage.
Inserts the key and value into local storage.
Inserts a batch of {key, value, opts} items.
Matches the given expression against the storage table.
Returns every non-expired row held in the backend's durable medium, without
touching its live view. {:ok, []} for backends without one; {:error, reason}
when the medium is unreadable.
Returns {module, ref} for the registry backend of the running hub
hub_id, the backend itself when given one, or nil if no such hub is
running.
Removes an entry from the storage.
Makes every write deferred with sync: false durable. :ok for backends
without a durable medium.
Updates the value for the key in local storage.
Types
A plain ETS table, a hub id (its registry backend), or an opened
{module, ref} backend such as the declared list's.
Functions
Deletes all objects from the storage table.
Never use in custom code. Should only be used for testing purposes.
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.
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.
Folds over all objects as {key, value}, dropping the trailing TTL element
that entries inserted with a :ttl carry.
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}.
Inserts the key and value into local storage.
Available options:
ttl: The time to live for the key in milliseconds.
Inserts a batch of {key, value, opts} items.
Backends implementing the optional insert_many/2 callback commit the
whole batch with a single write, so concurrent readers never observe a
partially applied batch. Other backends fall back to per-item inserts.
write_opts (sync: false) defers the backend's durable sync to a later
sync/1; backends without that callback ignore it and stay durable on
return.
Matches the given expression against the storage table.
The match_expr is a tuple that specifies the pattern.
Returns every non-expired row held in the backend's durable medium, without
touching its live view. {:ok, []} for backends without one; {:error, reason}
when the medium is unreadable.
read_durable/1 is an optional backend callback: a backend that does not
implement it is treated as having no durable medium.
Returns {module, ref} for the registry backend of the running hub
hub_id, the backend itself when given one, or nil if no such hub is
running.
Removes an entry from the storage.
Makes every write deferred with sync: false durable. :ok for backends
without a durable medium.
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.