I have a custom module for an online shop. Module's controller gets a product id which is sent by the user through a query string and puts it into the session. That is crucial for the shopping cart functionality.

Things are that, after clearing the cache, everything is ok, but after a few minutes/requests, the requests stop entering the controller. It seems like the response has been cached, even if:

  • I have disabled the caches at admin/config/development/performance,
  • I return '#cache' => ['max-age => 0] within the render array returned by the controller and
  • all responses come with the header "x-drupal-cache-max-age: 0 (Uncacheable)".

I also noticed that these errors usually come with the following apache error:

AH01070: Error parsing script headers
  • The error is probably only because you are trying to debug caching by enabling http.response.debug_cacheability_header. Otherwise this might be helpful drupal.stackexchange.com/questions/230169/…
    – 4uk4
    Jul 7, 2022 at 11:31
  • I think max-age => 0 doesn’t bubble properly in all cases without a patch. You can use query strings as cache contexts for better performance.
    – cilefen
    Jul 7, 2022 at 11:59
  • @cilefen you are right. If you want to disable cache on a controller you need to use this method: public function getCacheMaxAge(): int { return 0; } Jul 9, 2022 at 6:08
  • @4uk4 This was my problem! Thank you very much.
    – fombo
    Jul 9, 2022 at 10:25

1 Answer 1


If you want to disable the caching of a controller, use this method in your controller class:

   * @return int
  public function getCacheMaxAge(): int {
    return 0;
  • Good to know, thanks.
    – fombo
    Jul 9, 2022 at 10:27
  • Not necessary when you already return cache max-age in the render array and also it has no effect because a controller doesn't implement this method.
    – 4uk4
    Jul 9, 2022 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.