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

Default Crux.Structs.User cache.

Difference opposed to "regular" base caches.

  • Has me/0, me!/0 and me/1 functions to specify or retrieve the own user.

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.

Fetches the own user.

Sets the id of the own user, the data itself has to be inserted into the cache like usual.

Fetches the own user, raises if not cached.

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.

Fetches the own user.

Sets the id of the own user, the data itself has to be inserted into the cache like usual.

Fetches the own user, raises if not cached.

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.