crux_cache v0.2.0 Crux.Cache behaviour View Source
Behaviour all caches must implement. (Looking at custom ones you may want to write)
There are exceptions:
User cache:
- Implement a
me/1function setting the own user id - A
me/0andme!/0function getting the own user
- Implement a
Guild cache:
A bit more, you probably want to take a look at the code of the
Crux.Cache.GuildmoduleCustom caches should be put under a
Crux.Cache.Provider. (Can be combined with default caches)Also worth a look:
Crux.Cache.None- A dummyCrux.CacheandCrux.Cache.Provider, not caching anything.
Link to this section Summary
Callbacks
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 Types
key()
View Source
key() :: non_neg_integer()
key() :: non_neg_integer()
Default caches are using Discord Snowflakes as identifiers.
Link to this section Callbacks
delete(id)
View Source
delete(id :: key()) :: :ok
delete(id :: key()) :: :ok
Deletes data from the cache by key.
fetch(id) View Source
Fetches data from the cache by key.
fetch!(id)
View Source
fetch!(id :: identifier()) :: term() | no_return()
fetch!(id :: identifier()) :: term() | no_return()
Fetches data from the cache by key, raises if not found.
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)
start_link(args)
View Source
(optional)
start_link(args :: term()) :: Supervisor.on_start()
start_link(args :: term()) :: Supervisor.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.
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