Skip to content

Commit

Permalink
Merge pull request #314 from Kuadrant/easier_expiry
Browse files Browse the repository at this point in the history
Easier expiry
  • Loading branch information
alexsnaps authored May 8, 2024
2 parents 6e95dcc + d9fb111 commit 6073e60
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 3 additions & 1 deletion limitador/src/storage/redis/counters_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ impl CachedCounterValue {
}

pub fn requires_fast_flush(&self, within: &Duration) -> bool {
self.from_authority.load(Ordering::Acquire).not() || &self.value.ttl() <= within
self.from_authority.load(Ordering::Acquire).not()
|| self.expired_at(SystemTime::now())
|| &self.value.ttl() <= within
}
}

Expand Down
3 changes: 1 addition & 2 deletions limitador/src/storage/redis/redis_cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ impl AsyncCounterStorage for CachedRedisStorage {
let mut not_cached: Vec<&mut Counter> = vec![];
let mut first_limited = None;

let now = SystemTime::now();
// Check cached counters
for counter in counters.iter_mut() {
match self.cached_counters.get(counter) {
Some(val) if !val.expired_at(now) => {
Some(val) => {
if first_limited.is_none() && val.is_limited(counter, delta) {
let a =
Authorization::Limited(counter.limit().name().map(|n| n.to_owned()));
Expand Down

0 comments on commit 6073e60

Please sign in to comment.