I have a form that is prepopulated with information specific to an Anonymous user's session information.

However, the form appears to get cached for all anonymous users by default.

'Internal Dynamic Page Cache' is enabled, 'Internal Page Cache' is not.

How do I disable caching of this form? It should be rebuilt fresh every time it is displayed.

up vote 8 down vote accepted

To update:

In order to prevent a form from caching at all, you can include the following #cache key in your form:

$form['#cache'] = ['max-age' => 0];

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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