darkweak / souin

An HTTP cache system, RFC compliant, compatible with @tyktechnologies, @traefik, @caddyserver, @go-chi, @bnkamalesh, @beego, @devfeel, @labstack, @gofiber, @go-goyave, @go-kratos, @gin-gonic, @roadrunner-server, @zalando, @zeromicro, @nginx and @apache
https://docs.souin.io
MIT License
721 stars 56 forks source link

Surrogate key storage with default provider #306

Closed JacquesDurand closed 1 year ago

JacquesDurand commented 1 year ago

Hi !

I am currently trying to integrate souin as a caddy module for the api-platform distribution. Integration with xcaddy build works fine, and I managed to hit some cache quite easily. I have some issues concerning invalidation through surrogate keys when using the cdn default (souin) provider. It seems that no surrogate keys are stored, hence making purging irrelevant.

The workflow I setup is the following:

Purging the "non-surrogate" cache keys with PURGE https://localhost/souin-api/souin//greetings/1 does work but it is not the path we'd prefer to chose.

Here is my current Caddyfile:

{

    order cache before rewrite
    debug
    log {
        level debug
    }
    cache {
        allowed_http_verbs GET POST
        api {
            souin
        }
        cdn {
            provider default                         # I also tried with provider souin
        }
        nuts {                                             # I also tried with badger
            path /tmp/nuts
        }
        log_level debug
        key {
            disable_host
            disable_method
        }
        ttl 1000s
        timeout {
            backend 10s
            cache 100ms
        }
        default_cache_control public
    }
}

{$SERVER_NAME}
log {
    level debug
}

cache * {

}

... + base ApiPlatform stuff, Vulcain + Mercure etc

I was wondering if I was missing anything configuration-wise, or even if I misunderstood completely the way we're supposed to integrate surrogate keys. Thanks in advance for your help, if I can provide more details I'll be happy to ! PS: I am far from fluent in go, but if there is a PR to make i could also give it a try !

darkweak commented 1 year ago

Hello @JacquesDurand I think the documentation is not clear enough. In the cdn directive you have to set the dynamic directive because without that Souin only handles predefined keys. Maybe we could set the dynamic to true by default in the plugins/caddy/configuration.go file, it could be a quick win.

In your configuration example that would be


# previous
        cdn {
            dynamic
# Provider not needed, that's souin by default
#            provider default
        }
JacquesDurand commented 1 year ago

Hi @darkweak, thanks for the quick answer ! I just tested it and it does work with the "dynamic" option. Thanks a lot ! If that's okay with you I can try to make a PR asap to set "dynamic" to true by default in the caddy configuration