function form_set_cache

Stores a form in the cache.

Related topics

4 calls to form_set_cache()
drupal_process_form in drupal/core/includes/form.inc
Processes a form submission.
drupal_rebuild_form in drupal/core/includes/form.inc
Constructs a new $form from the information in $form_state.
FormCacheTest::testCacheToken in drupal/core/modules/system/lib/Drupal/system/Tests/Form/FormCacheTest.php
Tests the form cache with a logged-in user.
FormCacheTest::testNoCacheToken in drupal/core/modules/system/lib/Drupal/system/Tests/Form/FormCacheTest.php
Tests the form cache without a logged-in user.

File

drupal/core/includes/form.inc, line 567
Functions for form and batch generation and processing.

Code

function form_set_cache($form_build_id, $form, $form_state) {

  // 6 hours cache life time for forms should be plenty.
  $expire = 21600;

  // Cache form structure.
  if (isset($form)) {
    if ($GLOBALS['user']->uid) {
      $form['#cache_token'] = drupal_get_token();
    }
    Drupal::keyValueExpirable('form')
      ->setWithExpire($form_build_id, $form, $expire);
  }

  // Cache form state.
  if ($data = array_diff_key($form_state, array_flip(form_state_keys_no_cache()))) {
    Drupal::keyValueExpirable('form_state')
      ->setWithExpire($form_build_id, $data, $expire);
  }
}