diff --git a/core/includes/form.inc b/core/includes/form.inc
index 29b6c2d..2ca9c3b 100644
--- a/core/includes/form.inc
+++ b/core/includes/form.inc
@@ -575,8 +575,9 @@ function form_get_cache($form_build_id, &$form_state) {
  * Stores a form in the cache.
  */
 function form_set_cache($form_build_id, $form, $form_state) {
-  // 6 hours cache life time for forms should be plenty.
-  $expire = 21600;
+  // Form cache expiration should at least be the max age of the page itself to
+  // ensure AJAX functionality. In other situations, 6 hours should suffice.
+  $expire = max(21600, \Drupal::config('system.performance')->get('cache.page.max_age'));
 
   // Cache form structure.
   if (isset($form)) {
