cache-handler icon indicating copy to clipboard operation
cache-handler copied to clipboard

How to use with reverse_proxy? (caching is not working)

Open fa1rid opened this issue 8 months ago • 1 comments

Hi, I'm trying to use Caddy to cache .m3u8 files when reverse proxying to an upstream server. I’m using the cache directive and set up my Caddyfile as follows:

{
    order cache before rewrite
    order cache before reverse_proxy
    cache {
        allowed_http_verbs GET POST
        ttl 60s
        timeout {
            backend 20s
            cache 100ms
        }
    }
}

:9991 {
    route /ch1/* {
        @m3u8_files {
            path_regexp m3u8 ^/.*\.m3u8(\?.*)?$
        }

        handle @m3u8_files {
            header +X-Custom-Header "Some Value"
        }

        cache @m3u8_files {
            ttl 60s
        }

        uri strip_prefix /ch1
        rewrite * /ChannelOne{uri}
        reverse_proxy https://upstream-host.me {
            header_up Host {http.reverse_proxy.upstream.hostport}
        }
    }
}

What’s working:

  • The X-Custom-Header is successfully added to the .m3u8 responses.
  • The reverse proxy is functioning and serving content.

What’s not working:

  • The caching doesn't seem to take effect at all. I expected .m3u8 files to be cached for 60 seconds, but every request still hits the upstream server.

Any help or guidance would be appreciated. Thanks in advance!

fa1rid avatar Apr 04 '25 21:04 fa1rid

@fa1rid sorry for the delay, can you paste the curl command and the HTTP response headers? Maybe you're sending a Cache-Control: no-cache HTTP request header or you have a Cache-Control: no-store in the HTTP response headers.

darkweak avatar May 17 '25 08:05 darkweak