Skip to content

Commit

Permalink
Truncate cache if max_messages is set to a lower value at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivin committed Aug 29, 2024
1 parent c3d4a33 commit 18056b1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,16 @@ impl Cache {
///
/// By default, no messages will be cached.
pub fn set_max_messages(&self, max: usize) {
// Check to see if cache has to be truncated
if max < self.settings.read().max_messages {
for mut entry in self.messages.iter_mut() {
let message_queue = entry.value_mut();
while message_queue.len() > max {
message_queue.pop_front();
}
}
}

self.settings.write().max_messages = max;
}

Expand Down

0 comments on commit 18056b1

Please sign in to comment.