async-h1 icon indicating copy to clipboard operation
async-h1 copied to clipboard

Cache `Date` timestamps up to the minute

Open yoshuawuyts opened this issue 4 years ago • 2 comments

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.

yoshuawuyts avatar Nov 27 '20 13:11 yoshuawuyts

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.

JakeChampion avatar Dec 04 '20 17:12 JakeChampion

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.

Fishrock123 avatar Dec 04 '20 20:12 Fishrock123