rive_cache_inmemory/
builder.rs

1use crate::{Config, InMemoryCache};
2
3/// Builder to configure and construct an [`InMemoryCache`].
4///
5/// [`InMemoryCache`]: crate::InMemoryCache
6#[derive(Debug, Default)]
7#[must_use]
8pub struct InMemoryCacheBuilder(Config);
9
10impl InMemoryCacheBuilder {
11    /// Create a builder to configure and construct [`InMemoryCache`]
12    pub const fn new() -> Self {
13        Self(Config::new())
14    }
15
16    /// Set whether users should be cached.
17    pub fn cache_users(mut self, value: bool) -> Self {
18        self.0.cache_users = value;
19        self
20    }
21
22    /// Set whether servers should be cached.
23    pub fn cache_servers(mut self, value: bool) -> Self {
24        self.0.cache_servers = value;
25        self
26    }
27
28    /// Set whether channels should be cached.
29    pub fn cache_channels(mut self, value: bool) -> Self {
30        self.0.cache_channels = value;
31        self
32    }
33
34    /// Set whether messages should be cached.
35    pub fn cache_messages(mut self, value: bool) -> Self {
36        self.0.cache_messages = value;
37        self
38    }
39
40    /// Set whether emojis should be cached.
41    pub fn cache_emojis(mut self, value: bool) -> Self {
42        self.0.cache_emojis = value;
43        self
44    }
45
46    /// Set whether members should be cached.
47    pub fn cache_members(mut self, value: bool) -> Self {
48        self.0.cache_members = value;
49        self
50    }
51
52    /// Consume the builder, returning a configured cache.
53    pub fn build(self) -> InMemoryCache {
54        InMemoryCache::new_with_config(self.0)
55    }
56}