Crate twilight_cache_inmemory[][src]

Expand description


codecov badge discord badge github badge license badge rust badge

twilight-cache-inmemory is an in-process-memory cache for the [twilight-rs] ecosystem. It’s responsible for processing events and caching things like guilds, channels, users, and voice states.


By default no feature is enabled.


The permission-calculator feature flag will bring in support for the PermissionCalculator; an API for calculating permissions through it is exposed via InMemoryCache::permissions. Support for calculating the permissions of a member on a root guild-level and in a guild channel is included.

Refer to the permission module for more documentation.


Update a cache with events that come in through the gateway:

use std::env;
use futures::stream::StreamExt;
use twilight_cache_inmemory::InMemoryCache;
use twilight_gateway::{Intents, Shard};

let token = env::var("DISCORD_TOKEN")?;
let (shard, mut events) = Shard::new(token, Intents::GUILD_MESSAGES);

// Create a cache, caching up to 10 messages per channel:
let cache = InMemoryCache::builder().message_cache_size(10).build();

while let Some(event) = {
    // Update the cache with the event.


All first-party crates are licensed under ISC


pub use self::permission::InMemoryCachePermissions;


Iterators over the various resources stored in the cache.

Models built for utilizing efficient caching.


Calculate the permissions for members in on a guild- or channel-level with information from the cache.


Configuration for an InMemoryCache.

Resource associated with a guild.

A thread-safe, in-memory-process cache of Discord data. It can be cloned and sent to other threads.

Builder to configure and construct an InMemoryCache.

Retrieve statistics about the number of entities of each resource in the cache.

Immutable reference to a resource in the cache.

A set of bitflags which can be used to specify what resource to process into the cache.

Iterator over a voice channel’s list of voice states.


Implemented for dispatch events.