Proxy cache with redis storage and serving stale

Hello! Complete newbie to caddy server.

My use case is: I want to use caddy as a caching reverse proxy, which serves stale content whenever the origin server is down, a timeout occurs or origin replies with http 5xx. As storage for the cache I want to use redis. This is to use caddy as a proxy which makes a origin service more resilient to outages, and where stale content is better than no content.

Can I do this with the current caddy versions (1.x or 2.x) and if so, how does the config look like?

1 Like

Hey Ragnar, welcome!

You can almost do this in Caddy 2. I need to make two small enhancements.

The proxy module can do this if the backend is down or a timeout occurs, but I’d need to make a small enhancement for it this to be doable if the origin replies with 5xx. I am currently mulling over a few design choices and then I can commit and push the best one.

The second small enhancement I’d need to make is for the cache handler to have a mode where it only inserts into the cache unless an error is returned from a later handler, in which case it could read from the cache and write a response? Or some way to use the error routes: GitHub - caddyserver/caddy: Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Can you open an issue to request this, along with your thoughts/preferences? Link to this thread. Sign in to GitHub · GitHub

Would you be willing to test this when I implement it?

1 Like

Hello Matt,

I opened Serve stale content from cache if origin responds with 5xx · Issue #2 · caddyserver/cache-handler · GitHub and of course I am willing to test it.

Merry Christmas

2 Likes

Will this stuff be implemented in GitHub - nicolasazrak/caddy-cache: Caching middleware for caddy module (it lists “Serve stale content if proxy is down” in its TODO) @nicolasazrak

Thanks for the issue, will look into it soon!

(I can’t speak for the plugin’s author, but) that plugin is currently for Caddy 1; my plan is to implement it into Caddy 2.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.