Crux v2020-03-17 17:55:51Z Crux.Cache.Presence View Source

Default Crux.Structs.Presence cache.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Deletes data from the cache by key.

Fetches data from the cache by key.

Fetches data from the cache by key, raises if not found.

Inserts data into the cache.

Used to start anything fitting under a supervision tree, like for example a GenServer, instructed with handling the cache.

Inserts data into the cache.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

delete(id) View Source
delete(id :: Crux.Cache.key()) :: :ok

Deletes data from the cache by key.

Callback implementation for Crux.Cache.delete/1.

Link to this function

fetch(id) View Source
fetch(id :: Crux.Cache.key()) :: {:ok, term()} | :error

Fetches data from the cache by key.

Callback implementation for Crux.Cache.fetch/1.

Link to this function

fetch!(id) View Source
fetch!(id :: identifier()) :: {:ok, term()} | :error

Fetches data from the cache by key, raises if not found.

Callback implementation for Crux.Cache.fetch!/1.

Link to this function

insert(data) View Source
insert(data :: term()) :: term()

Inserts data into the cache.

Returns the atomified data allowing the operation to be chained.

For example something like that:

id =
  raw_data
  |> Cache.insert()
  |> Map.get(:id)

Callback implementation for Crux.Cache.insert/1.

Link to this function

start_link(args \\ []) View Source
start_link(args :: term()) :: GenServer.on_start()

Used to start anything fitting under a supervision tree, like for example a GenServer, instructed with handling the cache.

Optional, you maybe want to use external caching, e.g. Redis, not requiring anything like that.

Callback implementation for Crux.Cache.start_link/1.

Link to this function

update(data) View Source
update(data :: term()) :: term()

Inserts data into the cache.

Returns "updated" data including changes by merging.
For example from a message embed update to a full message object

content =
  partial_message # only contains `:id`, `:channel_id`, and `:embeds`
  |> Cache.update()
  |> Map.get(:content) # present if the message was cached previously

Callback implementation for Crux.Cache.update/1.