InMemoryCache

Struct InMemoryCache 

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

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

Uses DashMap for lock-free concurrent access. All stored values are wrapped in Arc for efficient sharing.

§TTL Behavior

  • Default TTL is 1 hour
  • Expired items are filtered out on read
  • Call InMemoryCache::sweep to remove expired items and free memory

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<Arc<Guild<'static>>>

Get a guild by ID.
Source§

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

Get a channel by ID.
Source§

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

Get a user by ID.
Source§

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

Get a guild member by guild and user ID.
Source§

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

Get a role by ID.
Source§

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

Insert a guild into the cache.
Source§

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

Insert a channel into the cache.
Source§

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

Insert a user into the cache.
Source§

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

Insert a guild member into the cache.
Source§

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

Insert a role into the cache.
Source§

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

Remove a guild from the cache.
Source§

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

Remove a channel from the cache.
Source§

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

Remove a user from the cache.
Source§

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

Remove a guild member from the cache.
Source§

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

Remove a role from the cache.
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.