API Platform - Changing max_age config value doesn't change the max-age request value

478 Views Asked by At

I have an application with API Platform and an other which consume my API.

I want to change the max-age value but when I change the value in the config, it doesn't change the value when I send a request...

Here is my config:

api_platform:
  ...
  http_cache:
    max_age: 600
  ...

And here is my request and response headers: request and response headers

Tell me what I'm doing wrong.

2

There are 2 best solutions below

2
On BEST ANSWER

The RFC discusses max-age here: Header Field Definitions
Also this page can help you a lot : Hypertext Transfer Protocol

The possible max-age value is dependent on browser/version and any proxy in the way.

It makes sense to apply to cache-control too in the absence of any explicit standards guidance.

It's as long as you should generally need anyway and picking any arbitrarily longer value could break some user-agents.

0
On

A possible explanation why the response cache headers are set to private and max-age=0 is that there is a session open (even if you don't use it). When that happens, the SessionListener will override the cache headers to disable it.

In order to fix this issue, you then just have to set stateless: true in the configuration of your firewall :

# config/packages/security.yaml
security:
    firewalls:
        main:
            stateless: true