aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorzeyla <[email protected]>2018-07-09 16:08:27 -0700
committerGitHub <[email protected]>2018-07-09 16:08:27 -0700
commite6026308b33c80aa33f0001c89cd271cc5cb6687 (patch)
tree2f8f50244c4d7a1234922fef61a72eb8dddbf4c5 /src/lib.rs
parentRemove deprecated use of Colour associated methods (diff)
downloadserenity-e6026308b33c80aa33f0001c89cd271cc5cb6687.tar.xz
serenity-e6026308b33c80aa33f0001c89cd271cc5cb6687.zip
Add a message cache API (#345)
This adds an API for message caching. By default this caches 0 messages per channel. This can be customized when instantiating: ```rust use serenity::cache::{Cache, Settings}; let mut settings = Settings::new(); // Cache 10 messages per channel. settings.max_messages(10); let cache = Cache::new_with_settings(settings); ``` After instantiation: ```rust use serenity::cache::Cache; let mut cache = Cache::new(); cache.settings_mut().max_messages(10); ``` And during runtime through the global cache: ```rust use serenity::CACHE; CACHE.write().settings_mut().max_messages(10); ```
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 196a3e0..74f050a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -202,6 +202,15 @@ lazy_static! {
/// println!("{}", CACHE.read().user.id);
/// ```
///
+ /// Update the cache's settings to enable caching of channels' messages:
+ ///
+ /// ```rust
+ /// use serenity::CACHE;
+ ///
+ /// // Cache up to the 10 most recent messages per channel.
+ /// CACHE.write().settings_mut().max_messages(10);
+ /// ```
+ ///
/// [`CurrentUser`]: model/struct.CurrentUser.html
/// [`Cache`]: cache/struct.Cache.html
/// [cache module documentation]: cache/index.html