pub struct CacheConfig { /* private fields */ }Expand description
Which resources the cache keeps, and how many entries of each.
CacheConfig::default keeps only guilds, channels and roles (and always the current
user), which covers most bots at the lowest cost (D-152). CacheConfig::discord_js
keeps what discord.js keeps by default. Customise either with CacheConfig::builder or
CacheConfigBuilder::from.
discord.js counterpart: the makeCache client option.
§Examples
use djs_cache::{CacheConfig, Limit, Resource};
let config = CacheConfig::builder()
.members(Limit::Unlimited)
.messages(Limit::Max(50))
.build();
assert_eq!(config.limit(Resource::Member), Limit::Unlimited);
assert_eq!(config.limit(Resource::Message), Limit::Max(50));
// Not mentioned: the default.
assert_eq!(config.limit(Resource::Guild), Limit::Unlimited);
assert_eq!(config.limit(Resource::Presence), Limit::Disabled);Implementations§
Source§impl CacheConfig
impl CacheConfig
Sourcepub fn builder() -> CacheConfigBuilder
pub fn builder() -> CacheConfigBuilder
Returns a builder that starts from the default configuration.
discord.js counterpart: Options.cacheWithLimits.
Sourcepub fn discord_js() -> Self
pub fn discord_js() -> Self
Returns discord.js’ default cache: every resource without a limit, except messages, which keep the latest 200 per channel.
discord.js counterpart: Options.cacheWithLimits(Options.DefaultMakeCacheSettings).
§Examples
use djs_cache::{CacheConfig, Limit, Resource};
let config = CacheConfig::discord_js();
assert_eq!(config.limit(Resource::Message), Limit::Max(200));
assert_eq!(config.limit(Resource::Presence), Limit::Unlimited);Sourcepub const fn limit(&self, resource: Resource) -> Limit
pub const fn limit(&self, resource: Resource) -> Limit
Returns the limit of resource.
discord.js counterpart: a manager’s entry in Options.cacheWithLimits.
Sourcepub const fn is_enabled(&self, resource: Resource) -> bool
pub const fn is_enabled(&self, resource: Resource) -> bool
Returns whether resource is cached.
discord.js counterpart: none (a manager’s cache always exists in discord.js).
Sourcepub const fn sweepers(&self) -> &SweepConfig
pub const fn sweepers(&self) -> &SweepConfig
Returns which sweeps run periodically (D-167). The cache itself runs nothing: the
djs-rs Client runs them, or call the Cache sweep methods yourself.
discord.js counterpart: the sweepers option of ClientOptions.
Trait Implementations§
Source§impl Clone for CacheConfig
impl Clone for CacheConfig
Source§impl Debug for CacheConfig
impl Debug for CacheConfig
Source§impl Default for CacheConfig
impl Default for CacheConfig
impl Eq for CacheConfig
Source§impl From<CacheConfig> for CacheConfigBuilder
impl From<CacheConfig> for CacheConfigBuilder
Source§fn from(config: CacheConfig) -> Self
fn from(config: CacheConfig) -> Self
Starts a builder from an existing configuration.