Sign in

    gaato/discord/cache does not have a README file

    CacheLimit

    pub struct CacheLimit {
    // private fields
    }

    Bounds one cached resource by entry count, lifetime, or both.

    Negative limits clamp to zero. A max_entries of zero retains nothing, while a ttl_ms of zero makes entries expire immediately. TTL deadlines are fixed when an entry is written and are never extended by reads; expiry is enforced lazily, without background timers: every read and event first releases whatever has expired, with what it owns or holds.

    CacheLimit::CacheLimit

    fn CacheLimit::CacheLimit(max_entries? : Int, ttl_ms? : Int64) -> CacheLimit

    Create an optional entry-count and TTL limit for one resource.

    CacheLimits

    pub struct CacheLimits {
    // private fields
    }

    Per-resource bounds for an in-memory cache.

    Guild, channel, DM-channel, user, and recent-user limits are global. Role, member, voice-state, and presence limits apply independently per guild; message limits apply independently per channel. Everything keyed by a guild or channel leaves with it: when a cached guild or channel is deleted, evicted by its limit, or expires, its roles, members, voice states, presences, channels, threads, and messages go too, and per-guild and per-channel maps are dropped once empty. State for a guild or channel the cache does not hold (its retention is off, or the event arrived after it left) still obeys its per-guild or per-channel limit and goes when the guild or channel is deleted.

    Under the defaults every structure is bounded:
    • guilds and unavailable-guild flags by the guilds the bot is in (a new session's READY also drops the guilds it no longer lists);
    • a guild's channels, roles, members, voice states, and presences by what Discord holds per guild, times those guilds (a fresh GUILD_CREATE drops the channels and threads it no longer lists);
    • threads by the active threads of those guilds: a thread leaves when it is deleted, archived, replaced by a thread list sync, or (private) when the bot is removed from it;
    • channels without a guild (DMs and group DMs) by dm_channels, 128, evicting the least recently written with its messages;
    • messages by messages, 100 per channel, times the channels above;
    • users by the entries that hold them (members, the authors of cached messages, and the current user), plus recent_users, the 128 most recently seen users nothing holds.

    Passing CacheLimit() for dm_channels, recent_users, or messages lifts that bound. TTLs use fixed, non-sliding deadlines set at write time (re-storing an entry sets a new one) and are enforced lazily without background timers.

    CacheLimits::CacheLimits

    fn CacheLimits::CacheLimits(guilds? : CacheLimit, channels? : CacheLimit, dm_channels? : CacheLimit, users? : CacheLimit, recent_users? : CacheLimit, roles? : CacheLimit, members? : CacheLimit, voice_states? : CacheLimit, presences? : CacheLimit, messages? : CacheLimit) -> CacheLimits

    Configure limits for each resource. Messages retain at most 100 entries per channel, DM channels and recent users at most 128 each; other resources have no limit beyond what keeps them bounded (see CacheLimits). The users limit applies to held users only.

    CacheLimits::default

    fn CacheLimits::default() -> CacheLimits

    The default per-resource limits (see CacheLimits).

    CacheResources

    pub struct CacheResources {
    // private fields
    }

    Selects which gateway resources an in-memory cache retains.

    Guilds, channels, roles, members, users, and voice states are enabled by default. Presences and messages are opt-in because they are high-churn and can dominate memory use on larger bots.

    CacheResources::CacheResources

    fn CacheResources::CacheResources(guilds? : Bool, channels? : Bool, roles? : Bool, members? : Bool, users? : Bool, voice_states? : Bool, presences? : Bool, messages? : Bool) -> CacheResources

    Select the retained resources individually; unspecified flags keep their defaults (all on except presences and messages).

    CacheResources::all

    Retain every resource, including high-churn presences and messages.

    CacheResources::default

    The default selection (see CacheResources).

    CacheResources::none

    Retain nothing; enable resources from this baseline for a minimal cache.

    InMemoryCache

    pub struct InMemoryCache {
    // private fields
    }

    A gateway-driven, resource-selective in-memory cache.

    update is the only mutation entry point. Entity getters return the model value retained by the cache; callers should treat it as immutable. List getters always allocate a new outer array so callers cannot mutate the cache's collections. Archived threads are not served: Discord stops sending their events, so the cache drops them when they are archived; fetch them over REST.

    InMemoryCache::InMemoryCache

    fn InMemoryCache::InMemoryCache(resources~ : CacheResources, limits? : CacheLimits, now? : () -> Int64) -> InMemoryCache

    Create an empty cache retaining the selected resources under the per-resource limits. Feed it gateway events via BotBuilder::attach_cache (or call update manually). TTL deadlines are fixed at write time and expiry is enforced lazily without background timers.

    InMemoryCache::channel

    The cached channel or thread, if retained.

    InMemoryCache::channels

    All cached channels and threads.

    InMemoryCache::guilds

    All cached guilds.

    InMemoryCache::is_guild_unavailable

    Whether the guild is currently marked unavailable by a GUILD_DELETE outage notice.

    InMemoryCache::members

    All cached members of a guild (only members seen in events unless the privileged GUILD_MEMBERS intent fills the cache).

    InMemoryCache::messages

    Cached messages of a channel, oldest first, capped by the messages limit.

    InMemoryCache::permissions

    Computes guild-level permissions from the cached guild, member, and roles.

    InMemoryCache::permissions_in

    Computes channel permissions using the cached base resources and channel overwrites. Returns None when any required cache resource is disabled or absent.

    InMemoryCache::unavailable_guilds

    Ids of guilds currently marked unavailable.

    InMemoryCache::update

    fn InMemoryCache::update(self : InMemoryCache, event :
    Event
    ) -> Unit

    Applies one decoded gateway event. Unsupported events are intentionally ignored for forward compatibility.

    InMemoryCache::user

    The cached user, if held by a cached entry or recently seen.

    InMemoryCache::users

    All cached users: those held by cached entries, then the recently seen.

    InMemoryCache::voice_state

    The cached voice state of a user in a guild, if any.

    InMemoryCache::voice_states

    All cached voice states of a guild.