[][src]Module serenity::cache

A cache of events received over a Shard, where storing at least some data from the event is possible.

This acts as a cache, to avoid making requests over the REST API through the http module where possible. All fields are public, and do not have getters, to allow you more flexibility with the stored data. However, this allows data to be "corrupted", and may or may not cause misfunctions within the library. Mutate data at your own discretion.

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 methods 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

Cache

A cache of all events received over a Shard, where storing at least some data from the event is possible.

CacheRwLock

A neworphantype to allow implementing AsRef<CacheRwLock> for the automatically dereferenced underlying type.

Settings

Settings for the cache.

Traits

CacheUpdate

Trait used for updating the cache with a type.

FromStrAndCache
StrExt