Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
Nafes CreditAttribution: Nafes commentedofry, 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. :-)
Тимофей, спасибо. Отличная идея. Давай подумаем, как сделать это лучше. Может даже создать для этой задачи отдельный модуль. И поставить тебя его совладельцем, если ты не против. :-)
Comment #2
Nafes CreditAttribution: Nafes commentedI 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.Comment #3
silurius CreditAttribution: silurius commentedJust a small comment about the PHP above: shouldn't it be using db_delete instead?
Comment #4
ofry CreditAttribution: ofry commenteddb_delete()? Maybe, but how to post inequities in options to pass it in db_delete()?
There is lack of documentation :(
Comment #5
silurius CreditAttribution: silurius commentedNo idea, sorry. :) I was just reading up on db_query and saw this:
There are a couple of examples in the comments on the db_delete page:
and
Comment #6
Nafes CreditAttribution: Nafes commentedConditions could be found. Just let me finish a busy project at work ...
Comment #7
Nafes CreditAttribution: Nafes commentedProject 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.
Comment #8
Nafes CreditAttribution: Nafes commentedDid you try the module OptimizeDB?
Comment #9
Nafes CreditAttribution: Nafes commented