#discord #discord-api #twilight

twilight-cache-inmemory

In-process-memory based cache for the Twilight ecosystem

30 releases (5 breaking)

new 0.5.0 Jun 13, 2021
0.4.2 May 30, 2021
0.3.4 Mar 14, 2021
0.2.5 Dec 30, 2020
0.2.3 Nov 29, 2020

#11 in Caching

Download history 49/week @ 2021-02-24 37/week @ 2021-03-03 93/week @ 2021-03-10 37/week @ 2021-03-17 232/week @ 2021-03-24 146/week @ 2021-03-31 175/week @ 2021-04-07 170/week @ 2021-04-14 109/week @ 2021-04-21 122/week @ 2021-04-28 79/week @ 2021-05-05 218/week @ 2021-05-12 130/week @ 2021-05-19 61/week @ 2021-05-26 66/week @ 2021-06-02 233/week @ 2021-06-09

585 downloads per month
Used in 2 crates

ISC license

1MB
22K 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 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);
shard.start().await?;

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

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–2.1MB
~45K SLoC