#discord #discord-api #twilight

twilight-cache-inmemory

In-process-memory based cache for the Twilight ecosystem

55 releases (11 breaking)

Uses new Rust 2021

0.11.0 May 15, 2022
0.10.2 Apr 15, 2022
0.10.1 Mar 20, 2022
0.8.3 Dec 27, 2021
0.2.3 Nov 29, 2020

#7 in Caching

Download history 449/week @ 2022-01-30 185/week @ 2022-02-06 172/week @ 2022-02-13 140/week @ 2022-02-20 199/week @ 2022-02-27 165/week @ 2022-03-06 325/week @ 2022-03-13 354/week @ 2022-03-20 86/week @ 2022-03-27 173/week @ 2022-04-03 136/week @ 2022-04-10 161/week @ 2022-04-17 371/week @ 2022-04-24 412/week @ 2022-05-01 444/week @ 2022-05-08 1167/week @ 2022-05-15

2,411 downloads per month
Used in 5 crates (4 directly)

ISC license

1.5MB
33K 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.

Statistics

Statistics can be an important debugging tool for determining how large a cache is or determining whether a cache has an expected amount of resources within it. An interface for retrieving statistics about the amount of a resource within the cache as a whole or on a guild-level can be retrieved via [InMemoryCache::stats].

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).await?;
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

~2–2.8MB
~54K SLoC