Some bad-written modules can flood cache_form records, so this table size can be measured in some GB!
Drupal core ISN'T cleared expired records in this table, so this table can increase... and increase... until it will ruin site because base exceeds the disk space quota of your hosting provider :(
I can't clear it even press "Clear all caches" link.

Solution:
Add this hook_cron

function MYMODULE_cron() {
  db_query("DELETE FROM cache_form where 'expire' < UNIX_TIMESTAMP();");
}

Comments

Nafes’s picture

ofry, thanks! Very good idea. Let us think a bit, how to do it better. Maybe even to make a separate module for this task. And put you as a co-maintainer as well, if you don't mind. :-)

Тимофей, спасибо. Отличная идея. Давай подумаем, как сделать это лучше. Может даже создать для этой задачи отдельный модуль. И поставить тебя его совладельцем, если ты не против. :-)

Nafes’s picture

I have found a good problem discussion here. You are right, the problem is of high interest. Also a related module Safe cache_form Clear is mentioned. But it uses drush command drush safe-cache-form-clear. Your idea is different and I don't see any module implementing this.

silurius’s picture

Just a small comment about the PHP above: shouldn't it be using db_delete instead?

ofry’s picture

db_delete()? Maybe, but how to post inequities in options to pass it in db_delete()?
There is lack of documentation :(

silurius’s picture

No idea, sorry. :) I was just reading up on db_query and saw this:

Do not use this function for INSERT, UPDATE, or DELETE queries. Those should be handled via db_insert(), db_update() and db_delete() respectively.

There are a couple of examples in the comments on the db_delete page:


<?php
$and = db_and()->condition('mid', 1)->condition('cache_type', 'year');
db_delete('mid_cache_index')->condition($and)->execute();   

// Above translates to:
DELETE FROM {mid_cache_index}  WHERE ( (mid = 1) AND (cache_type = 'year') )
?>

and

<?php
db_delete('mid_cache_index')
  ->condition('mid', 1)
  ->condition('cache_type', 'year')
  ->execute();
?>
Nafes’s picture

Conditions could be found. Just let me finish a busy project at work ...

Nafes’s picture

Project DB Cache Clear has been created to handle this issue and also #2409377: Add option to clear all cache tables using 1 button and by cron. The release is going to be created soon.

Nafes’s picture

Did you try the module OptimizeDB?

Nafes’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.