#discord #discord-api #twilight

twilight-cache-inmemory

In-process-memory based cache for the Twilight ecosystem

2 unstable releases

0.1.0 Sep 13, 2020
0.0.0 Aug 30, 2020

#26 in Caching

25 downloads per month
Used in 2 crates

ISC license

525KB
14K SLoC

twilight-cache-inmemory

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.

Examples

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

use std::env;
use tokio::stream::StreamExt;
use twilight_cache_inmemory::InMemoryCache;
use twilight_gateway::Shard;

let token = env::var("DISCORD_TOKEN")?;
let mut shard = Shard::new(token);
shard.start().await?;

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

let mut events = shard.events();

while let Some(event) = events.next().await {
    // Update the cache with the event.
    cache.update(&event);
}

License

All first-party crates are licensed under ISC

Dependencies

~1.3–2MB
~42K SLoC