#discord #discord-api #twilight

twilight-cache-inmemory

In-process-memory based cache for the Twilight ecosystem

21 unstable releases (3 breaking)

new 0.3.1 Jan 19, 2021
0.2.9 Jan 19, 2021
0.2.5 Dec 30, 2020
0.2.3 Nov 29, 2020

#11 in Caching

Download history 34/week @ 2020-09-30 42/week @ 2020-10-07 138/week @ 2020-10-14 66/week @ 2020-10-21 76/week @ 2020-10-28 79/week @ 2020-11-04 71/week @ 2020-11-11 39/week @ 2020-11-18 77/week @ 2020-11-25 42/week @ 2020-12-02 52/week @ 2020-12-09 156/week @ 2020-12-16 10/week @ 2020-12-23 56/week @ 2020-12-30 117/week @ 2021-01-06 68/week @ 2021-01-13

305 downloads per month
Used in 2 crates

ISC license

660KB
17K SLoC

Ruby 15K SLoC // 0.0% comments Rust 2.5K SLoC // 0.0% comments

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 futures::stream::StreamExt;
use twilight_cache_inmemory::InMemoryCache;
use twilight_gateway::{Intents, Shard};

let token = env::var("DISCORD_TOKEN")?;
let mut shard = Shard::new(token, Intents::GUILD_MESSAGES);
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.2–2MB
~41K SLoC