#discord #discord-api #twilight

twilight-cache-inmemory

In-process-memory based cache for the Twilight ecosystem

42 releases (8 breaking)

new 0.8.0 Dec 3, 2021
0.7.2 Nov 20, 2021
0.7.1 Oct 29, 2021
0.6.0 Jul 31, 2021
0.2.3 Nov 29, 2020

#5 in Caching

Download history 111/week @ 2021-08-15 71/week @ 2021-08-22 111/week @ 2021-08-29 70/week @ 2021-09-05 126/week @ 2021-09-12 133/week @ 2021-09-19 113/week @ 2021-09-26 153/week @ 2021-10-03 546/week @ 2021-10-10 231/week @ 2021-10-17 137/week @ 2021-10-24 191/week @ 2021-10-31 375/week @ 2021-11-07 525/week @ 2021-11-14 279/week @ 2021-11-21 585/week @ 2021-11-28

1,794 downloads per month
Used in 2 crates

ISC license

1.5MB
31K SLoC

twilight-cache-inmemory

codecov badge 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.

Features

By default no feature is enabled.

permission-calculator

The permission-calculator feature flag will bring in support for the PermissionCalculator; an API for calculating permissions through it is exposed via InMemoryCache::permissions. Support for calculating the permissions of a member on a root guild-level and in a guild channel is included.

Refer to the permission module for more documentation.

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.2–2MB
~44K SLoC

wa