hikari.internal.cache#

Various utilities that may be used in a cache-impl.

Module Contents#

class hikari.internal.cache.BaseData[source]#

Bases: abc.ABC, Generic[ValueT]

A data class used for in-memory storage of entities in a more primitive form.

Note

This base implementation assumes that all the fields it’ll handle will be immutable and to handle mutable fields you’ll have to override build_entity and build_from_entity to explicitly copy them.

abstract build_entity(app, /)[source]#

Build an entity object from this data object.

Parameters:
apphikari.traits.RESTAware

The hikari application the built object should be bound to.

Returns:
ValueT

The initialised entity object.

abstract classmethod build_from_entity(entity, /)[source]#

Build a data object from an initialised entity.

Parameters:
entityValueT

The entity object to build a data class from.

Returns:
DataT

The built data class.

class hikari.internal.cache.Cache3DMappingView(items)           Cache3DMappingView(items, *, builder)[source]#

Bases: CacheMappingView[hikari.snowflakes.Snowflake, hikari.api.cache.CacheView[KeyT, ValueT]]

A special case of the Mapping View which avoids copying the immutable values contained within it.

class hikari.internal.cache.CacheMappingView(items)           CacheMappingView(items, *, builder)[source]#

Bases: hikari.api.cache.CacheView[KeyT, ValueT]

A cache mapping view implementation used for representing cached data.

Parameters:
itemstyping.Union[typing.Mapping[KeyT, ValueT], typing.Mapping[KeyT, DataT]]

A mapping of keys to the values in their raw forms, wrapped by a ref wrapper or in a data form.

buildertyping.Optional[typing.Callable[[DataT], ValueT]]

The callable used to build entities before they’re returned by the mapping. This is used to cover the case when items stores DataT objects.

get_item_at(index, /)[source]#
get_item_at(index: slice, /) Sequence[ValueT]

Get an item at a specific position or slice.

class hikari.internal.cache.EmptyCacheView[source]#

Bases: hikari.api.cache.CacheView[Any, Any]

An empty cache view implementation.

get_item_at(index)[source]#

Get an item at a specific position or slice.

class hikari.internal.cache.GuildRecord[source]#

An object used for storing guild specific cached information in-memory.

This includes references to the cached entities that “belong” to the guild by ID if it’s globally unique or by object if it’s only unique within the guild.

channels: Optional[MutableSet[hikari.snowflakes.Snowflake]][source]#

A set of the IDs of the guild channels cached for this guild.

This will be None if no channels are cached for this guild else typing.MutableSet[hikari.snowflakes.Snowflake] of channel IDs.

emojis: Optional[MutableSet[hikari.snowflakes.Snowflake]][source]#

A set of the IDs of the emojis cached for this guild.

This will be None if no emojis are cached for this guild else typing.MutableSet[hikari.snowflakes.Snowflake] of emoji IDs.

guild: Optional[hikari.guilds.GatewayGuild][source]#

A cached guild object.

This will be hikari.guilds.GatewayGuild or None if not cached.

invites: Optional[MutableSequence[str]][source]#

A set of the str codes of the invites cached for this guild.

This will be None if no invites are cached for this guild else typing.MutableSequence[str] of invite codes.

is_available: Optional[bool][source]#

Whether the cached guild is available or not.

This will be None when no GuildRecord.guild is also None else bool.

members: Optional[hikari.internal.collections.ExtendedMutableMapping[hikari.snowflakes.Snowflake, RefCell[MemberData]]][source]#

A mapping of user IDs to the objects of members cached for this guild.

This will be None if no members are cached for this guild else hikari.internal.collections.ExtendedMutableMapping[hikari.snowflakes.Snowflake, MemberData].

presences: Optional[hikari.internal.collections.ExtendedMutableMapping[hikari.snowflakes.Snowflake, MemberPresenceData]][source]#

A mapping of user IDs to objects of the presences cached for this guild.

This will be None if no presences are cached for this guild else hikari.internal.collections.ExtendedMutableMapping[hikari.snowflakes.Snowflake, MemberPresenceData].

roles: Optional[MutableSet[hikari.snowflakes.Snowflake]][source]#

A set of the IDs of the roles cached for this guild.

This will be None if no roles are cached for this guild else typing.MutableSet[hikari.snowflakes.Snowflake] of role IDs.

stickers: Optional[MutableSet[hikari.snowflakes.Snowflake]][source]#

A sequence of sticker IDs cached for this guild.

This will be None if no stickers are cached for this guild else typing.Sequence[hikari.snowflakes.Snowflake] of emoji IDs.

threads: Optional[MutableSet[hikari.snowflakes.Snowflake]][source]#

A set of the IDs of the guild threads cached for this guild.

This will be None if no threads are cached for this guild else typing.MutableSet[hikari.snowflakes.Snowflake] of thread IDs.

voice_states: Optional[hikari.internal.collections.ExtendedMutableMapping[hikari.snowflakes.Snowflake, VoiceStateData]][source]#

A mapping of user IDs to objects of the voice states cached for this guild.

This will be None if no voice states are cached for this guild else hikari.internal.collections.ExtendedMutableMapping[hikari.snowflakes.Snowflake, VoiceStateData].

empty()[source]#

Check whether this guild record has any resources attached to it.

Returns:
bool

Whether this guild record has any resources attached to it.

class hikari.internal.cache.InviteData[source]#

Bases: BaseData[hikari.invites.InviteWithMetadata]

A data model for storing invite data in an in-memory cache.

class hikari.internal.cache.KnownCustomEmojiData[source]#

Bases: BaseData[hikari.emojis.KnownCustomEmoji]

A data model for storing known custom emoji data in an in-memory cache.

class hikari.internal.cache.MemberData[source]#

Bases: BaseData[hikari.guilds.Member]

A data model for storing member data in an in-memory cache.

class hikari.internal.cache.MemberPresenceData[source]#

Bases: BaseData[hikari.presences.MemberPresence]

A data model for storing presence data in an in-memory cache.

class hikari.internal.cache.MessageData[source]#

Bases: BaseData[hikari.messages.Message]

A model for storing message data in an in-memory cache.

class hikari.internal.cache.MessageInteractionData[source]#

Bases: BaseData[hikari.messages.MessageInteraction]

A model for storing message interaction data.

class hikari.internal.cache.RefCell[source]#

Bases: Generic[ValueT]

Object used to track mutable references to a value in multiple places.

This is intended to enable reference counting for entities that are only kept alive by reference (e.g. the unknown emoji objects attached to presence activities and user objects) without the use of a “Data” object which lowers the time spent building these entities for the objects that reference them.

copy()[source]#

Get a copy of the contents of this cell.

Returns:
ValueT

The copied contents of this cell.

class hikari.internal.cache.RichActivityData[source]#

Bases: BaseData[hikari.presences.RichActivity]

A data model for storing rich activity data in an in-memory cache.

class hikari.internal.cache.VoiceStateData[source]#

Bases: BaseData[hikari.voices.VoiceState]

A data model for storing voice state data in an in-memory cache.

hikari.internal.cache.copy_guild_channel(channel)[source]#

Logic for handling the copying of guild channel objects.

This exists account for the permission overwrite objects attached to guild channel objects which need to be copied themselves.

hikari.internal.cache.unwrap_ref_cell(cell)[source]#

Unwrap a RefCell instance to it’s contents.

Parameters:
cellRefCell[ValueT]

The reference cell instance to unwrap.

Returns:
ValueT

The reference cell’s content.

hikari.internal.cache.DataT[source]#

Type-hint for “data” objects used for storing and building entities.

hikari.internal.cache.KeyT[source]#

Type-hint for mapping keys.

hikari.internal.cache.ValueT[source]#

Type-hint for mapping values.