dunglas / symfony-docker

A Docker-based installer and runtime for Symfony. Install: download and `docker compose up`.
https://dunglas.dev/2021/12/symfonys-new-native-docker-support-symfony-world/
2.47k stars 733 forks source link

Cache-header never changed #137

Closed h-rafiee closed 3 years ago

h-rafiee commented 3 years ago

Hello Dear Dunglas,

I change all type max-age in config, entity but always send max-age = 0 , s-maxage= 3600 but i wan't change it to

http_cache:
        invalidation:
            enabled: true
            varnish_urls: [ '%env(VARNISH_URL)%' ]
        max_age: 3600
        shared_max_age: 3600
        vary: ['Content-Type', 'Authorization', 'Origin']
        public: true

i can set bresp.http.cache-header in varnish.vcl manually and it's work but it's static way i want dynamic way to configure caching system per each entity or global side

here is my varnish.vcl

```vcl vcl 4.0; import std; backend default { .host = "caddy"; .port = "80"; # Health check #.probe = { # .url = "/"; # .timeout = 5s; # .interval = 10s; # .window = 5; # .threshold = 3; #} } # Hosts allowed to send BAN requests acl invalidators { "localhost"; "php"; } sub vcl_recv { if (req.restarts > 0) { set req.hash_always_miss = true; } # Remove the "Forwarded" HTTP header if exists (security) unset req.http.forwarded; # Remove "Preload" and "Fields" HTTP header to improve Vulcain's performance unset req.http.preload; unset req.http.fields; # To allow API Platform to ban by cache tags if (req.method == "BAN") { if (client.ip !~ invalidators) { return (synth(405, "Not allowed")); } if (req.http.ApiPlatform-Ban-Regex) { ban("obj.http.Cache-Tags ~ " + req.http.ApiPlatform-Ban-Regex); return (synth(200, "Ban added")); } return (synth(400, "ApiPlatform-Ban-Regex HTTP header must be set.")); } # For health checks if (req.method == "GET" && req.url == "/healthz") { return (synth(200, "OK")); } } sub vcl_hit { if (obj.ttl >= 0s) { # A pure unadulterated hit, deliver it return (deliver); } if (std.healthy(req.backend_hint)) { # The backend is healthy # Fetch the object from the backend return (restart); } # No fresh object and the backend is not healthy if (obj.ttl + obj.grace > 0s) { # Deliver graced object # Automatically triggers a background fetch return (deliver); } # No valid object to deliver # No healthy backend to handle request # Return error return (synth(503, "API is down")); } sub vcl_deliver { # Don't send cache tags related headers to the client unset resp.http.url; # Comment the following line to send the "Cache-Tags" header to the client (e.g. to use CloudFlare cache tags) unset resp.http.Cache-Tags; } sub vcl_backend_response { # set beresp.http.cache-control = "public, max-age=3600"; set beresp.ttl = 24h; set beresp.grace = 1h; } ```

maxhelias commented 3 years ago

Hi! Please do not post your issue on every project.. (https://github.com/api-platform/api-platform/issues/1895)

This project doesn't use varnish. Please keep the issue tracker for project related topics.