I use Varnish for my API platform endpoints in a symfony app. API platform version is 2.6 and since I made an upgrade to PHP 8, cache_headers option from API platform config is not working anymore.
I have this configuration for a specific api platform endpoint
collectionOperations:
voucher_list:
method: GET
cache_headers:
max_age: 3600
shared_max_age: 3600
path: /account/{account_id}/vouchers
requirements:
account_id: 'd+'
normalization_context:
groups: ['voucher_list:read']
This worked perfectly with php 7.4.
Now, Cache-Control has the value no-cache on this endpoint.
Cache-Control will be set only if I set the default configuration in api_platform.yaml
http_cache:
max_age: 3600
shared_max_age: 3600
vary: ['Accept']
public: true
2
Answers
This issue was fixed with update to latest version of api platform
In your collection operations
cache_headers
, max age is defined asmax-age
instead ofmax_age
As i see in this documentation https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers
max_age
seems the correct param name.As you can see in your generic configuration, you correctly set
max_age
forhttp_cache
Even in api platform 2.6 https://api-platform.com/docs/v2.6/core/performance/#setting-custom-http-cache-headers