Before I say this is a bug, I am going to explore it as a support request.

I had "skip hash" selected on the node import settings form.

I noticed that my cache_form was insanely huge (110M) with just one person testing/developing.

We noticed that most of the forms were from a feeds import that we had.

I wonder if there is a way to exclude certain forms from cache. Specifically I would like to exclude my feeds form, or the node the importer is attached to, from being cached in cache_form.

Comments

MegaChriz’s picture

Status: Active » Fixed

The form cache works differently compared to Drupal's other caches. Drupal uses the form cache to validate if the posted values belong to fields that were in the form. Therefore, I don't think that it's possible to exclude forms from the form cache. Form cache getting huge is also a general Drupal problem. If you search for "drupal form cache huge" you will find a lot of reports about this issue. Some people reported that their form cache even grew gigabytes big.

Feeds does have a lot of forms on the importer configuration. Each "section" (e.g., "Basic settings", "Fetcher settings", "Change processor", etc.) is it's own form. Also, up until the 7.x-2.0-alpha8 version, Feeds wasn't efficient on the importer configuration: on each page load it checked for fetcher, parser and processor if they provided settings by loading it's specific settings form, meaning that three extra forms were loaded and cached. This inefficiency was fixed in #2307379: Add FeedsConfigurable::hasConfigForm().

MegaChriz’s picture

Oops, forget to mention a good workaround.

What I did for one site where form cache was huge, was clean up old entries in this cache more often. By default, Drupal keeps entries in the form cache for at least 6 hours, and that's a hard-coded value, see form_set_cache() from includes/form.inc:

function form_set_cache($form_build_id, $form, $form_state) {
  // 6 hours cache life time for forms should be plenty.
  $expire = 21600;

I changed this to clear up entries after 1 hour by implementing hook_cron() in a custom module:

/**
 * Implements hook_cron().
 */
function mymodule_cron() {
  mymodule_flush_cache_form();
}

/**
 * Flushes cache_form based on *created* timestamp.
 *
 * This is done because the expire timestamp of a cache_form entry is hard-coded.
 * cache_form entries older than 1 hour will be deleted.
 */
function mymodule_flush_cache_form() {
  // No minimum cache lifetime, flush all temporary cache entries now.
  db_delete('cache_form')
    ->condition('expire', CACHE_PERMANENT, '<>')
    ->condition('created', REQUEST_TIME - 3600, '<')
    ->execute();
}

You could of course change the logic a bit to only clear Feeds related forms.

SocialNicheGuru’s picture

Status: Fixed » Needs work

how would I clear just the cache_form entries associated with feeds?
In cache I only see cache_form and cache_form_state.

SocialNicheGuru’s picture

This might do the trick:
https://www.drupal.org/node/795044#comment-3516124

 cache_clear_all('form_'. $_POST['form_build_id'], 'cache_form');
vakulrai’s picture

The OptimizeDB module might do the trick with following functionalities:-

1)Ability to clean cache_form .
2)Optimize DB tables.

Please follow the link:-
https://www.drupal.org/project/optimizedb