Module serenity::cache

source ·
Available on crate feature cache only.
Expand description

A cache containing data received from Shards.

Using the cache allows to avoid REST API requests via the http module where possible. Issuing too many requests will lead to ratelimits.

§Use by Models

Most models of Discord objects, such as the Message, GuildChannel, or Emoji, have methods for interacting with that single instance. This feature is only compiled if the model feature is enabled. An example of this is Guild::edit, which performs a check to ensure that the current user is the owner of the guild, prior to actually performing the HTTP request. The cache is involved due to the function’s use of unlocking the cache and retrieving the Id of the current user, and comparing it to the Id of the user that owns the guild. This is an inexpensive method of being able to access data required by these sugary methods.

§Do I need the Cache?

If you’re asking this, the answer is likely “definitely yes” or “definitely no”; any in-between tends to be “yes”. If you are low on RAM, and need to run on only a couple MB, then the answer is “definitely no”. If you do not care about RAM and want your bot to be able to access data while needing to hit the REST API as little as possible, then the answer is “yes”.

Structs§

Traits§

  • Trait used for updating the cache with a type.

Type Aliases§