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

Allow users to specify different DefaultMaxAges for different cached paths

Open rickles42 opened this issue 6 years ago • 0 comments

It would be useful if Caddy could treat different cached paths differently, like how Caddy's header directive works. However, looking at setup.go it appears that DefaultMaxAge and other options are global to the whole middleware.

If I try to specify multiple cache blocks in my Caddyfile, Caddy doesn't complain, but I don't see the behavior I would expect:

    cache {
        match_path /foo
        default_max_age 1m
        status_header First-Block-Header
    }

    cache {
        match_path /bar
        match_path /baz
        default_max_age 5m
        status_header Second-Block-Header
    }

In this case I'm not sure whether Caddy is actually instantiating multiple instances of caddy-cache, or if one of the blocks is just getting ignored, but I see all responses using a single same status header.

I suppose a revised syntax would look more like the syntax of header:

    cache /foo {
        default_max_age 1m
        status_header First-Block-Header
    }

    cache /bar /baz {
        default_max_age 5m
        status_header Second-Block-Header
    }

rickles42 avatar Jul 08 '18 18:07 rickles42