Struct InMemoryCache

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

An in-memory cache of Revolt data.

To use a cache instance in multiple tasks, consider wrapping it in an std::sync::Arc or std::rc::Rc.

Implementations§

Source§

impl InMemoryCache

Source

pub fn new() -> Self

Create new InMemoryCache instance with default Config.

Source

pub fn new_with_config(config: Config) -> Self

Create new InMemoryCache instance with provided Config.

Source

pub const fn builder() -> InMemoryCacheBuilder

Create a new builder to configure and construct an in-memory cache.

Source

pub fn clear(&self)

Clear the cache.

Source

pub const fn stats(&self) -> InMemoryCacheStats<'_>

Create an interface for retrieving cache statistics.

Example:

use rive_cache_inmemory::InMemoryCache;

let cache = InMemoryCache::new();

// later in the code...
let messages = cache.stats().messages();
println!("messages count: {messages}");
Source

pub const fn iter(&self) -> InMemoryCacheIter<'_>

Create an interface for iterating over the various resources in the cache.

Example:

use rive_cache_inmemory::InMemoryCache;

let cache = InMemoryCache::new();

// later in the code...
for user in cache.iter().users() {
    println!("{}: {}#{}", user.id, user.username, user.discriminator);
}
Source

pub fn user(&self, id: &str) -> Option<Reference<'_, String, User>>

Get a user by ID.

Source

pub fn server(&self, id: &str) -> Option<Reference<'_, String, Server>>

Get a server by ID.

Source

pub fn channel(&self, id: &str) -> Option<Reference<'_, String, Channel>>

Get a channel by ID.

Source

pub fn message(&self, id: &str) -> Option<Reference<'_, String, Message>>

Get a message by ID.

Source

pub fn emoji(&self, id: &str) -> Option<Reference<'_, String, Emoji>>

Get an emoji by ID.

Source

pub fn member( &self, id: &MemberCompositeKey, ) -> Option<Reference<'_, MemberCompositeKey, Member>>

Get a member by MemberCompositeKey.

Source

pub fn update(&self, event: &impl CacheUpdate)

Update the cache with an incoming event.

Trait Implementations§

Source§

impl Debug for InMemoryCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for InMemoryCache

Source§

fn default() -> InMemoryCache

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> Same for T

Source§

type Output = T

Should always be Self
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.