twilight-cache-inmemory
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.
Examples
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};
# #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
let token = env::var("DISCORD_TOKEN")?;
let shard = Shard::new(token, Intents::GUILD_MESSAGES);
shard.start().await?;
let cache = InMemoryCache::builder().message_cache_size(10).build();
let mut events = shard.events();
while let Some(event) = events.next().await {
cache.update(&event);
}
# Ok(()) }
License
All first-party crates are licensed under ISC