async-h1
async-h1 copied to clipboard
Cache `Date` timestamps up to the minute
As pointed out by @Fishrock123 in https://github.com/http-rs/async-h1/pull/158/files#r530051517, Node.js caches timestamps for a minute, making it much easier to handle requests at a high volume. We should consider adopting this approach as well.
Here is a rust version which is similar in implementation to the Node.js version:
use cached::proc_macro::cached;
#[cached(size=1, time=60)]
fn utc_date() -> String {
fmt_http_date(SystemTime::now())
}
I would contribute this but I'm not too sure how to write a test to exercise this feature yet.
Given this is a perf change, a benchmark is probably more appropriate.
Also, regarding it being a perf change, it may be better to write this logic ourselves rather than go though the extra key-value map that is in cached, despite how neat that crate is.