caddyserver/cache-handler

Bypass req/res headers

stpp2 opened this issue ยท 4 comments

Hi again @darkweak (and Caddy team) and thanks for all your hard work ๐Ÿ™

I'm implementing the Cache Handler on my existing Caddy server and hit a dead end around cache control config.
Trying to force the browser to never locally cache anything, while always caching requests on the Caddy server.

Thought this should be straight forward by using mode bypass and setting something like default_cache_control "must-revalidate, private, max-age=0". (also tried to set the default headers or downstream headers directly via Caddy)

This doesn't seem to work as it forces both the server and the browser to request for a fresh response.
Also tried to add something like s-maxage=100 but this caches in both. All my attempts so far result in either caching in both the server + browser or not caching at all.

I know this is probably not in line with the RFC, but I was hoping there's a way to configure things differently. Am I missing anything to make that work?

Hey @stpp2 why do you say the mode bypass doesn't solve your issue?

Hi @darkweak,

Thanks for the follow up.
Here's the config I've tried using -

  cache {
		default_cache_control "must-revalidate, private, max-age=0, s-maxage=100"
		allowed_http_verbs GET
		mode bypass
		stale 0
		ttl 10s
		redis {
			configuration {
				...
		}
		timeout {
			cache 3s
		}
  }

I've tried a few variations of the default_cache_control but couldn't get the Caddy server to always use cache while never cache in the browser. (either both worked or both didn't work)

Am I missing something here?

The default_cache_control directive will set the Cache-Control header if it has not been set by the upstream. In your case you can omit that or just set a no-store because you're using the mode bypass.

Got it. I'll have to run more tests here to get a better picture.
Thanks for the help!

(will close for now and re-open if anything changes)