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

Missing varnish configuration for API-Platform workflow #1824

Open
vasilvestre opened this issue Oct 27, 2023 · 6 comments
Open

Missing varnish configuration for API-Platform workflow #1824

vasilvestre opened this issue Oct 27, 2023 · 6 comments

Comments

@vasilvestre
Copy link

vasilvestre commented Oct 27, 2023

https://api-platform.com/docs/core/performance/#enabling-the-built-in-http-cache-invalidation-system does not contains any information about how APIP works with varnish.

This part in particular :

    if (req.http.ApiPlatform-Ban-Regex) {
      ban("obj.http.Cache-Tags ~ " + req.http.ApiPlatform-Ban-Regex);

      return (synth(200, "Ban added"));
    }
@dunglas
Copy link
Member

dunglas commented Oct 27, 2023

Indeed, this docs entry needs to be updated.

The VCL to use is here: https://github.com/api-platform/api-platform/blob/v2.1.6/docker/varnish/conf/default.vcl (cc @dbu).

Also, we're in the process of integrating the Caddy Cache handler (which uses Souin) to replace Varnish: api-platform/api-platform#2383

@vasilvestre
Copy link
Author

The VCL to use is here: https://github.com/api-platform/api-platform/blob/v2.1.6/docker/varnish/conf/default.vcl (cc @dbu).

Do you want me to create the PR or do you notify dbu so he change the entry?

Also, we're in the process of integrating the Caddy Cache handler (which uses Souin) to replace Varnish: api-platform/api-platform#2383

I totally prefer this but changing existing nginx isn't a light task

@dbu
Copy link
Contributor

dbu commented Oct 27, 2023

i do not plan to do a pull request for it, glad if you want to do it @vasilvestre

and i just notice in the example that you invalidate tags with ban. this works, but if you have a lot of traffic and frequent bans, this can put a high overhead on varnish. the best way to handle tags is with the varnish xkey module.

(the banlist needs to be checked against every request, and is a regex on the tags header. with xkey, varnish creates an optimized tree to look up keys so it can immediately invalidate the caches with those tags and avoid overhead)

@vasilvestre
Copy link
Author

@dbu the part about xkey is documented in the documentation right ? Your point is that the vcl from dunglas don't handle this one case ?

@dbu
Copy link
Contributor

dbu commented Oct 27, 2023

ah i did not look at the documentation. yeah that mentions xkey but the vcl needs to handle it as well. (and the doc could explain why xkey are preferred over ban)

@soyuka
Copy link
Member

soyuka commented Oct 28, 2023

It's on my todolist to improve this but I'm stuck with website issues, feel free to propose a documentation for xkey.

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

4 participants