#discord #discord-api #twilight

twilight-cache-inmemory

In-process-memory based cache for the Twilight ecosystem

24 releases

new 0.3.5 Apr 11, 2021
0.3.4 Mar 14, 2021
0.3.1 Jan 19, 2021
0.2.5 Dec 30, 2020
0.2.3 Nov 29, 2020

#10 in Caching

Download history 10/week @ 2020-12-23 56/week @ 2020-12-30 117/week @ 2021-01-06 94/week @ 2021-01-13 62/week @ 2021-01-20 38/week @ 2021-01-27 51/week @ 2021-02-03 212/week @ 2021-02-10 116/week @ 2021-02-17 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 153/week @ 2021-04-07

432 downloads per month
Used in 2 crates

ISC license

665KB
17K 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 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–1.9MB
~40K SLoC