View Source ProcessHub.Service.Storage (ProcessHub v0.3.2-alpha)

The local storage service provides API functions for managing local storage. This is mainly used for storing data that is not required to be persisted.

Local storage is implemented using ETS tables and is cleared periodically.

Summary

Functions

Deletes all objects from the ETS table.

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

Exports all objects from the ETS table.

Returns the value for the key in local storage.

Inserts the key and value into local storage.

Removes an entry from the storage.

Updates the value for the key in local storage.

Types

@type table_id() :: atom()

Functions

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

Deletes all objects from the ETS 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 ETS 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()

Inserts the key and value into local storage.

Available options:

  • ttl: The time to live for the key in milliseconds.
@spec remove(table_id(), term()) :: boolean()

Removes an entry from the storage.

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.