Jump to content

Hi.

I've coded a minimal c++ web server, and now I wanna start adding more things and make it as smooth and perfect as possible.

I'm starting with caching.

Now, I can send the typical stuff in the response headers that'll make the browser give me back either a "If-None-Match" if I'm doing ETags or a If-Modified-Since if I'm using dates.

 

Now what I'm asking is which one would be more optimized?

I honestly don't know how to make ETags an easy task, it could be really useful in long-term caching for pages that won't be changed in a long period of time, but is it really worth it? I mean I see no really simple way of doing, either store it in file comments (which would go against the purpose, given you'd have to check metadata for that), I could make a global variable, like an array or some other object to store every single page's ETag, which would make it really hard to update pages if you're trying to access them as you're developing or editing, because you'd either have to change that variable manually or make something to check whenever the file was modified.

This would be nice for pages that only got an update every once in a while and was highly requested, but any other case would make it clunky. Not mentioning long term caching can't really be that useful, I mean what are the chances you're gonna keep a page cached in a browser for say 1 or 2 months?

 

Second Option: Last-Modified + If-Modified-Since + Checking File Metadata for last modified date every time.

Which doesn't seem too much of a compromise until you start getting a lot of requests. I don't know at what point this becomes not-worth it compared to ETags?

I figure it's still way better than sending the whole file every time, but that's not even really an option so..

I could just go ahead and code the database program, which would be optimized and would be able to handle ETags the best way possible, but that can take a while and I want to understand this first.

Maybe I could do it sort of like a hybrid, I'd config each page as ET or MD and handle it all as such.

 

But I need someone's opinion.

I'm unexperienced, I don't know until what point storage can be powerful in order to handle looking into metadata a lot of times or if I should make it more scalable by handling those ETags to memory, or whether that'd happen at all if I did.

 

Thank you.

Link to comment
https://linustechtips.com/topic/670386-etags-vs-checking-metadata/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×