I am working on a Drupal 7 site. When I check the
cache_form table it reaches 4 GB daily so I have to manually
cache_form table. Is there any way to clear
cache_form table automatically 4 times in a day?
There are several method to clear the cache_form automatically.
Use optimizedb module
There is well-known issue with fast-growing table cache_form. This table stores Drupal form cache and it isn’t cleared when you flush all cache or run cron. Also you can struggle with problem of fragmentation with InnoDB tables on active delete/insert operations. This module provide functionality to solve this problem. Also its provide additional tools for maintenance database.
Module OptimizeDB provide such features:
Ability to clean **cache_from** in administrative page or do it by cron. Ability to optimize all database’s tables and display its sizes. Configuration of notification about necessity to perform maintenance tasks. Perform check and repair operation with tables. Prevent crashing tables when perform all maintained actions.
If you have drush access Safe cache_form Clear module
Safely remove a limited number of items from the cache_form table.
This module provides a drush command drush safe-cache-form-clear that can be run at a high frequency, keeping the table at a reasonable size. It requires that you use the database cache back-end for the cache_form table.
Drupal's core cron can have problems clearing out the cache_form table when it grows extremely large. This module works around this by limiting the number of items expired from the cache in a single run, dealing with a manageable chunk each time.
You can configure the number of items deleted in a single run by setting the $conf['safe_cache_form_clear_limit'] persistent variable.
for automatically clear the Drupal cache use Cleaner module (it's not clear the cache_form table).
The Cleaner module allows the admin to set a schedule for clearing caches, watchdog, and old sessions.
and another solution is create a custom route in your module something that not predictable by others (some hash url), on call back function truncate 'cache_form' table (or equivalent Drupal ) then on your server or your Cpanel create a crontab,schedule it to run the code periodically.