InMemoryCache

Struct InMemoryCache 

Source
pub struct InMemoryCache { /* private fields */ }
Expand description

In-memory cache for Discord entities with Time-To-Live (TTL).

Implementations§

Source§

impl InMemoryCache

Source

pub fn new() -> Self

Create a new empty cache with default TTL (1 hour).

Source

pub fn with_ttl(ttl: Duration) -> Self

Create a new cache with a custom TTL.

Source

pub fn sweep(&self) -> usize

Garbage collect expired items.

Returns the number of items removed.

Trait Implementations§

Source§

impl Cache for InMemoryCache

Source§

fn guild(&self, id: Snowflake) -> Option<Guild<'static>>

Source§

fn channel(&self, id: Snowflake) -> Option<Channel<'static>>

Source§

fn user(&self, id: Snowflake) -> Option<User<'static>>

Source§

fn member( &self, guild_id: Snowflake, user_id: Snowflake, ) -> Option<GuildMember<'static>>

Source§

fn role(&self, id: Snowflake) -> Option<Role<'static>>

Source§

fn insert_guild(&self, guild: Guild<'static>)

Source§

fn insert_channel(&self, channel: Channel<'static>)

Source§

fn insert_user(&self, user: User<'static>)

Source§

fn insert_member(&self, guild_id: Snowflake, member: GuildMember<'static>)

Source§

fn insert_role(&self, id: Snowflake, role: Role<'static>)

Source§

impl Default for InMemoryCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.