aboutsummaryrefslogtreecommitdiff
path: root/src/client/context.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-22 21:20:46 -0800
committerAustin Hellyer <[email protected]>2016-11-22 21:20:46 -0800
commit41820989b48fe803867e19cadde557ea090f99bd (patch)
tree601480f55c0358ae0963257307cbd2019423dec0 /src/client/context.rs
parentRename the State to Cache (diff)
downloadserenity-41820989b48fe803867e19cadde557ea090f99bd.tar.xz
serenity-41820989b48fe803867e19cadde557ea090f99bd.zip
Change the CACHE to be an RwLock
The global Cache used to be an Arc<Mutex>, however the issue is that it could only be opened for reading or writing once at a time. With an RwLock, multiple readers can access the Cache at once, while only one Writer may at once. This will allow users to be able to have multiple Readers open at once, which should ease some of the pains with working with the Cache. Upgrade path: Modify all uses of the CACHE from: `CACHE.lock().unwrap()` to `CACHE.read().unwrap()` if reading from the Cache (most use cases), or `CACHE.write().unwrap()` to write to it.
Diffstat (limited to 'src/client/context.rs')
-rw-r--r--src/client/context.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/client/context.rs b/src/client/context.rs
index 67c0146..25424fb 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -762,7 +762,7 @@ impl Context {
let role_id = role_id.into();
feature_cache! {{
- let cache = CACHE.lock().unwrap();
+ let cache = CACHE.read().unwrap();
let role = if let Some(role) = {
cache.get_role(guild_id.0, role_id.0)
@@ -825,7 +825,7 @@ impl Context {
let channel_id = channel_id.into();
feature_cache_enabled! {{
- if let Some(channel) = CACHE.lock().unwrap().get_channel(channel_id) {
+ if let Some(channel) = CACHE.read().unwrap().get_channel(channel_id) {
return Ok(channel.clone());
}
}}
@@ -838,7 +838,7 @@ impl Context {
let guild_id = guild_id.into();
feature_cache_enabled! {{
- let cache = CACHE.lock().unwrap();
+ let cache = CACHE.read().unwrap();
if let Some(guild) = cache.get_guild(guild_id) {
return Ok(guild.channels.clone());
@@ -903,7 +903,7 @@ impl Context {
let user_id = user_id.into();
feature_cache_enabled! {{
- let cache = CACHE.lock().unwrap();
+ let cache = CACHE.read().unwrap();
if let Some(member) = cache.get_member(guild_id, user_id) {
return Ok(member.clone());