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
Serve stale content from cache if origin responds with 5xx #2
Comments
I define stale content as content for which the cache-control max-age has already expired, but it is to be kept in the cache anyway and served as a fallback if the origin is unresponsive/responds with errors |
@mholt I think this issue should be moved to https://github.com/caddyserver/cache-handler |
@francislavoie Agreed -- and this feature should be pretty easy to implement. Caddy has a ResponseRecorder which can help the cache decide whether to respond or not. |
@rrva are you still interested in this and/or willing to test an implementation? |
@gc-ss Sorry, no interest has faded for the moment (not using caddy in this capacity right now). |
Maybe we can take into count |
Should this issue be moved to https://github.com/darkweak/souin ? |
In the Souin codebase we support the stale-if-error directive |
@darkweak do you think it might be possible to make it configurable and not depending on upstream response cache-control? I would like to enable fallback to server STALE page in case my upstream goes down. |
@fliespl you may use the |
@darkweak thanks - do you have any example of that? I have tried a few things without success... |
I'm not sure but it could be something like this (cc @francislavoie about
Or using the
|
@darkweak actually, I was not able to use this. Steps tried: Simple test.php file with: Cache-Control: I get cached on first request, disable php upstream. Cache works for 10 seconds and after that I get bad gateway 502 error and not stale content. Souin; fwd=uri-miss; key=GET-https-example.com-/test.php; detail=SERVE-HTTP-ERROR STALE_GET-https-example.com-/test.php still has ttl of 3471 seconds. Am I missing something? |
@fliespl what's your request? (curl) |
curl https://domain No matter if it's GET / HEAD same output. |
If your request doesn't send a |
@darkweak isn't stale-if-error only response header? I haven't seen any browser utilizing it for "request". I would assume it's origin response to cache servers that instructs them that in case they fail, cache server is allowed to serve this content to client. |
I meant use the max-stale request directive sorry |
@darkweak okay so my initial request still stands - allow serving stale content no matter what request sends (since max-stale is not used). Maybe it should allow it if mode is bypass request the same way it does for no-cache? |
Yes, I will create a PR for that! 👍 |
@darkweak also found one other issue which is probably connected. At default setup (without souin) if reverse proxy (php fastcgi) returns status 500 with html it gets displayed (i.e. wordpress error: https://ss.codeone.pl/ss-2024-01-21-22-20-19-1705872019-F83puPwH.png) With souin enabled I get empty response and default chrome error: https://ss.codeone.pl/ss-2024-01-21-22-21-00-1705872060-HGzbuNTQ.png I feel like it's a bug somewhere with souin altering proxy response/headers. |
@fliespl there is a PR already open for that darkweak/souin#441 (thanks to @vejipe) 😄 |
As requested in this forum thread, I want to be able to use caddy as a reverse caching proxy which makes an service more resilient to outages of the origin server, so that if the origin goes down or responds with errors, caddy serves old content.
Specifically:
Also attaching a corresponding nginx.conf which achieves what I want for reference.
nginx.conf.gz
The text was updated successfully, but these errors were encountered: