-
Notifications
You must be signed in to change notification settings - Fork 166
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
Hash-based etag layer #324
Comments
Yeah we could have something like that. The issue is that it requires buffering the whole response body in the middleware which doesn't work for streaming responses but for responses made using |
Our axum web server is now behind cloudflare, so this is basically at the bottom of my priorities list. I started working on it, but I want to make sure I get the most out of cloudflare before this, since there are downsides, like the CPU needed to hash and the buffering. By the way, huge thank you to everyone working on tokio, tower, and axum, and the massive long tail of dependencies which enabled us to ship something great. We are up to 13 million requests per day, around 150 qps, and we absolutely could not have done this without tower. Everything we do is open source and CC0, so everywhere it makes sense we want to upstream. Thank you! ❤️ |
I'm curious, who is 'we'? |
Oh 😐 |
I think it could make sense to implement this for |
Rather than hashing whole file, I would suggest to consider computing etag from last modified timestamp, length and optionally hash of file name |
Hashing the filename is useless, since renaming the file will result in it
having a different URL and cache key anyway. Hashing the length doesn't help
much either, as there are types of files whose length never changes, such as
the index.html built by build tools that just insert a hash of scripts into
it. Hashing the last modified time has the opposite issue: It can easily
change without the file itself changing.
…---------- Původní e-mail ----------
Od: Douman ***@***.***>
Komu: tower-rs/tower-http ***@***.***>
Kopie: SvizelPritula ***@***.***>, Comment ***@***.***
github.com>
Datum: 3. 7. 2023 7:24:13
Předmět: Re: [tower-rs/tower-http] Hash-based etag layer (Issue #324)
"
Rather than hashing whole file, I would suggest to consider computing etag
from last modified timestamp, length and optionally hash of file name
—
Reply to this email directly, view it on GitHub
(#324 (comment)),
or unsubscribe
(https://github.com/notifications/unsubscribe-auth/AHYWLAODUGSC3UE62HPL3QDXOJJPRANCNFSM6AAAAAAUGZWSVA)
.
You are receiving this because you commented. Message ID: <tower-rs/tower-
***@***.***>
"
|
Related: tower-rs/tower#692. This seems like a pretty often requested feature |
I've started on an implementation at https://github.com/billythedummy/tower-etag-cache/tree/master/tower-etag-cache. The implemented |
@billythedummy I am also interested in this feature, so I had a look at your implementation and example. I tested the caching behaviour with the index.css file of your example app:
But in step 4, the server should return the new file (as it has been modified). |
@Weltpilot thank you for the review. I wanted to just do a basic proof-of-concept with the |
If you assume that all resources are static and don't change, why not simply always return "304 Not Modified", |
@Weltpilot does not change throughout the lifetime of the server. What this enables:
|
@billythedummy So, when you want to change a static file, you need to restart the server? Sorry, that doesn't make any sense to me. |
I think the best path is to develop it as a standalone crate, unless it specifically needs private API for tower-http, that we can’t just make public. tower-http doesn’t get much maintenance these days (personally I’m busy with work and axum) so don’t wanna add more stuff to tower-http which further burdens maintainers. |
I'm thinking about writing a hash-based etag layer.
My plan is to:
If-Match
with a matching etag value and the response code is 200, set the code to 304 and remove the bodyI probably can't contribute what I wrote to tower-http, since I'm very busy with the project that this is for, but if I wind up writing it I can definitely post or link to the code, in case a tower-http contributor is interested in getting it into tower-http. Also, even if it doesn't get into tower-http, it might give some insight into the viability of the approach.
Some reasons why this might not be a good idea:
Any thoughts on the viability of this approach are welcome, especially if it's been considered for tower-http. I've been looking around for other applications that automatically add etags using a hash function, and I haven't found many. This makes me wonder if the idea is actually wrothwhile.
The text was updated successfully, but these errors were encountered: