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

Varnish Cache Refresh Triggering HTML Requests Instead of JSON (HTTP 406) #146

Open
qguillou-niji opened this issue Feb 21, 2025 · 4 comments
Assignees

Comments

@qguillou-niji
Copy link

I'm using this bundle on my Sulu project, which has a Varnish cache configured.

When a page is modified, the cache invalidation is performed automatically, but I also see a cache refresh being performed on the current page and its child pages via GET requests on the page URLs.
These GET calls are made without the ".json" suffix at the end of the URL, so Sulu tries to respond with the HTML format, which is not supported by my Sulu project. This results in an HTTP 406 error response, which in turn leads to error logs.

Nothing impactful, everything seems to work correctly, but I'm wondering if there's a configuration that could address this error? (Prevent cache refresh, make the call in JSON format, or other options).

Thank you in advance for your feedback.

@alexander-schranz
Copy link
Member

@qguillou-niji If you are using varnish you should also enable tag based caches. Sulu purges the URL + a Tag referencing the page - this tag is written on all URL which did use that page for rendering. Sulu have tag based caching enabled by default also for the php based http cache. For varnish you need also enable it I think it is this documentation: https://docs.sulu.io/en/2.6/cookbook/caching-with-varnish.html#using-xkey /cc @wachterjohannes

@qguillou-niji
Copy link
Author

Thank you for your response @alexander-schranz .
I have followed the required configuration in the link you sent, including:

  • commenting out the lines in public/index.php,
  • the Varnish configuration,
  • the Sulu HTTP cache configuration as you can find below.
sulu_http_cache:
    tags:
        enabled: true
    cache:
        max_age: 86400
        shared_max_age: 86400
    proxy_client:
        symfony:
            enabled: false # disable this when varnish is used
        varnish:
            enabled: true
            servers:
                - '%env(resolve:VARNISH_URL)%'
            tag_mode: purgekeys

@alexander-schranz
Copy link
Member

@qguillou-niji best is you share your whole vcl as that is responsible for the cache invalidation to work. Then @wachterjohannes can give you maybe some hints where the errors in your vcl is.

@qguillou-niji
Copy link
Author

The Varnish VCL configuration is based on the documentation at https://docs.sulu.io/en/2.6/cookbook/caching-with-varnish.html#varnish-configuration but with specificities as it manages multiple domains, unfortunately in its current state I cannot send it.

To return to the problem I am encountering, it does not concern the invalidation which works well but the refresh which follows the invalidation.
Suppose I have a page whose URL is the following "/en/blog", when I modify the page in Sulu BO, the cache is indeed invalidated then a refresh request GET /en/blog is sent. Except that I use Sulu only in headless mode, so this request returns an HTTP 406 "406 error response "Found" from caching proxy" (vendor/friendsofsymfony/http-cache/src/Exception/ProxyResponseException.php:32)
It would be necessary either to have a refresh call in GET /en/blog.json or not to have a refresh, I guess.

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

3 participants