Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surrogate key storage with default provider #306

Closed
JacquesDurand opened this issue Feb 14, 2023 · 2 comments
Closed

Surrogate key storage with default provider #306

JacquesDurand opened this issue Feb 14, 2023 · 2 comments

Comments

@JacquesDurand
Copy link
Contributor

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:

  • POST a resource (in this case a "Greeting")
  • GET said resource ( GET https://localhost/greetings/1 ). First call misses cache, subsequent ones hit flawlessly
  • At this point, GET https://localhost/souin-api/souin/ returns a list of cached keys, but GET https://localhost/souin-api/souin/surrogate_keys returns an empty list
  • Purging through surrogate keys ( PURGE https://localhost/souin-api/souin/ with the headers { "Surrogate-Key": "/greetings, /greetings/1" } ) returns a 204, but since I believe no key was stored in the first place, it does not have a real impact on the cache itself

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
Copy link
Owner

darkweak commented Feb 14, 2023

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants