Crate twilight_cache_inmemory[][src]

Expand description

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 = 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

Modules

model

Models built for utilizing efficient caching.

Structs

Config

Configuration for an InMemoryCache.

InMemoryCache

A thread-safe, in-memory-process cache of Discord data. It can be cloned and sent to other threads.

InMemoryCacheBuilder

Builder to configure and construct an InMemoryCache.

InMemoryCacheStats

Retrieve statistics about the number of entities of each resource in the cache.

ResourceType

A set of bitflags which can be used to specify what resource to process into the cache.

Traits

UpdateCache