Crux v2020-03-17 17:55:51Z Crux.Cache.Emoji View Source
Default Crux.Structs.Emoji
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
child_spec(init_arg) View Source
Returns a specification to start this module under a supervisor.
See Supervisor
.
delete(id)
View Source
delete(id :: Crux.Cache.key()) :: :ok
delete(id :: Crux.Cache.key()) :: :ok
Deletes data from the cache by key.
Callback implementation for Crux.Cache.delete/1
.
fetch(id)
View Source
fetch(id :: Crux.Cache.key()) :: {:ok, term()} | :error
fetch(id :: Crux.Cache.key()) :: {:ok, term()} | :error
Fetches data from the cache by key.
Callback implementation for Crux.Cache.fetch/1
.
fetch!(id)
View Source
fetch!(id :: identifier()) :: {:ok, term()} | :error
fetch!(id :: identifier()) :: {:ok, term()} | :error
Fetches data from the cache by key, raises if not found.
Callback implementation for Crux.Cache.fetch!/1
.
insert(data) View Source
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
.
start_link(args \\ [])
View Source
start_link(args :: term()) :: GenServer.on_start()
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
.
update(data) View Source
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
.