Why _transient_dirsize_cache Can Slow Down Your Site
The _transient_dirsize_cache key stores cached directory sizes so WordPress can speed up disk-usage checks for updates, uploads, and cron. If a plugin/custom code saves this transient with autoload enabled, hundreds of KB can be loaded into memory on every page view and hurt performance.
Check Your Autoload Size (on/auto/off)
Measure total autoload size and find the heaviest options. (This setup uses autoload = ‘on’ | ‘auto’ | ‘off’.)
-- Total autoload size (KB)
SELECT ROUND(SUM(OCTET_LENGTH(option_value)) / 1024, 2) AS autoload_kb
FROM wp_options
WHERE autoload IN ('on','auto');
-- Top 20 heaviest autoloaded options
SELECT option_name,
ROUND(OCTET_LENGTH(option_value) / 1024, 2) AS size_kb
FROM wp_options
WHERE autoload IN ('on','auto')
ORDER BY OCTET_LENGTH(option_value) DESC
LIMIT 20;
Detecting _transient_dirsize_cache
Check size and autoload state directly:
SELECT option_name, autoload,
ROUND(OCTET_LENGTH(option_value) / 1024, 2) AS size_kb
FROM wp_options
WHERE option_name IN ('_transient_dirsize_cache', '_transient_timeout_dirsize_cache');
Fixing Autoload Bloat with SQL
Keep the data but disable autoload immediately:
UPDATE wp_options
SET autoload = 'off'
WHERE option_name IN ('_transient_dirsize_cache', '_transient_timeout_dirsize_cache');
Or delete and let WordPress regenerate it cleanly:
DELETE FROM wp_options
WHERE option_name IN ('_transient_dirsize_cache', '_transient_timeout_dirsize_cache');
Preventing Recurrence with PHP
Force these transients to stay non-autoloaded:
<?php
/**
* Force autoload='off' for dirsize_cache transients (on/auto/off setup).
*/
add_action('added_option', function ($option, $value) {
static $targets = ['_transient_dirsize_cache', '_transient_timeout_dirsize_cache'];
if (in_array($option, $targets, true)) {
global $wpdb;
$wpdb->update($wpdb->options, ['autoload' => 'off'], ['option_name' => $option]);
}
}, 10, 2);
add_action('updated_option', function ($option, $old_value, $value) {
static $targets = ['_transient_dirsize_cache', '_transient_timeout_dirsize_cache'];
if (in_array($option, $targets, true)) {
global $wpdb;
$wpdb->update($wpdb->options, ['autoload' => 'off'], ['option_name' => $option]);
}
}, 10, 3);
// Optional: manual reset via admin URL
add_action('admin_init', function () {
if (isset($_GET['reset_dirsize_cache']) && current_user_can('manage_options')) {
delete_transient('dirsize_cache');
add_action('admin_notices', function () {
echo '<div class="notice notice-success"><p>The dirsize_cache transient has been deleted.</p></div>';
});
}
});
WP-CLI Quick Fixes
# Total autoload size (on/auto)
wp db query "SELECT ROUND(SUM(OCTET_LENGTH(option_value))/1024, 2) AS autoload_kb FROM wp_options WHERE autoload IN ('on','auto');" --skip-column-names
# Inspect the dirsize_cache transients
wp db query "SELECT option_name, autoload, ROUND(OCTET_LENGTH(option_value)/1024, 2) AS size_kb FROM wp_options WHERE option_name IN ('_transient_dirsize_cache','_transient_timeout_dirsize_cache');"
# Delete the transient so WordPress can rebuild it
wp transient delete dirsize_cache
# Force autoload='off' if needed
wp db query "UPDATE wp_options SET autoload='off' WHERE option_name IN ('_transient_dirsize_cache','_transient_timeout_dirsize_cache');"
Safe Cleanup Workflow (Production)
- Back up the
wp_optionstable. - Measure autoload size and list heavy options.
- Inspect and update/delete
_transient_dirsize_cache. - Add the PHP snippet to enforce
autoload='off'. - Re-check totals to confirm the fix.
Multisite Considerations
For multisite, related transients live in wp_sitemeta as _site_transient_dirsize_cache and _site_transient_timeout_dirsize_cache. Run equivalent checks/updates on that table.
Conclusion
Autoload bloat is a silent performance killer. Keep _transient_dirsize_cache out of autoload, audit regularly, and enforce autoload='off' to maintain a fast, stable site.
Comments