-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cached value #288
Cached value #288
Conversation
6df11ef
to
aad9e79
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see I'm not entirely happy with things as they are...
But this could be a start, and certainly fixes the issue we had. In any case, putting this up for review by you smart folks! I need some input...
- user_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wherever (probably I) that got removed, that was a mistake
@@ -5,22 +5,19 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; | |||
#[derive(Debug)] | |||
pub(crate) struct AtomicExpiringValue { | |||
value: AtomicI64, | |||
expiry: AtomicU64, // in microseconds | |||
expiry: AtomicExpiryTime, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think encapsulating that behavior made sense, regardless of the change... but now that I needed reusing that very same thing... it was time ;)
self.expiry.duration() | ||
} | ||
|
||
#[allow(dead_code)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is annoying, it's dead code when compiling for wasm... I don't think we should fail the build when that happens tho. Dead code for that target is fine, it's all DCE'd anyways...
let cache_ttl = self.ttl_from_redis_ttl( | ||
redis_ttl_ms, | ||
counter.seconds(), | ||
counter_val, | ||
counter.max_value(), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably should be folded in the CachedCounterValue
type... more specifically its constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes more sense to use moka's cache and keep track of the counter values with the AtomicExpiringValue
, also, a nice refactor done to that one. This changes drastically the way I'll be updating the cache once I get the updated values from Redis, so hopefully will be merged soon :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also looks good to me. The changes all seem to be make sense and it's nice to have all the logic contained in these new types
This fixes the issue when a partition lasts longer than a counter's time window and all the increments from the previous window get batched with the current one, resulting in limiting the requests too early