-
Notifications
You must be signed in to change notification settings - Fork 93
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
Cache responses for unauthenticated users #75
Conversation
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 wonder what the best way to test this is, to make sure nginx is properly doing caching.
Our isomorphic server, doing local requests, makes this a little complicated to think about.
maybe caching static content like images for all users with a larger valid period will also help reduce the load. Also noticed that the cache control header needs tuning too.
|
@dessalines This PR sets the header |
|
||
# Response cache for unauthenticated users | ||
proxy_cache lemmy_cache_{{domain}}; | ||
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504; |
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.
adding updating
can also help here to reduce requests to upstream, when an object expires out of the cache.
templates/nginx.conf
Outdated
# Response cache for unauthenticated users | ||
proxy_cache lemmy_cache_{{domain}}; | ||
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; | ||
proxy_cache_valid 1m; |
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'd be up for increasing this also.
@Nutomic anything preventing merging this?
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 deployed it on https://voyager.lemmy.ml/ just now, and it seems to work well. Data is getting cached as expected when user is logged out, and not cached when user is logged in. I also didnt find any leakage of private data.
Though it would be good to update it for using LemmyNet/lemmy-ui#1641 once that is deployed as its a bit cleaner.
I had this deployed on lemmy.ml but its not working. The site was logging me out whenever I opened a new tab, and sometimes there were generic error messages which wouldnt go away. We have to wait until there is proper caching support in the projects themselves. Edit: generic error messages are still happening so those are unrelated to caching, but Im not getting logged out anymore. |
This can potentially reduce server load a lot because unauthenticated users trigger much fewer database queries. It will only be effective once lemmy-ui switches from websocket and uses the http api (Lemmy 0.18).
It works fine in a quick test, but will need more testing to make sure it doesnt accidentally leak private data. For now I deployed it on ds9.lemmy.ml