-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Replace time crate with httpdate #4169
Conversation
examples/tinyhttp.rs
Outdated
let now = time::get_time(); | ||
if now >= cache.next_update { | ||
cache.update(now); | ||
if let Ok(since_last_update) = cache.last_update.elapsed() { | ||
if since_last_update > Duration::from_secs(1) { | ||
cache.update(); | ||
} |
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.
It seems like this would misbehave if the clock is moved backwards, though that was probably also the case previously.
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 could be resolved by using Instant
for cache & SystemTime
only for generating string
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.
That would work. Another approach would be to always regenerate if the time has gone backwards.
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 see now that the goal of the cache isn't to cache the date for a second, but to cache the date for that particular second
Code updated to store unix second & refresh when second changes
httpdate is used by hyper/warp/headers, & this addresses the time crate used here being 0.1 while latest time crate is 0.3
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.
Thanks.
httpdate is used by hyper/warp/headers,
& this addresses the time crate used here being 0.1 while latest time crate is 0.3