What this solution does
The 'Old Cache Cleanup' module automatically removes only outdated cache files on a schedule, freeing disk space without slowing down the site. Fresh cache data remains untouched.
Folders /bitrix/cache/, /bitrix/managed_cache/, /bitrix/stack_cache/, /bitrix/html_pages/, and /upload/resize_cache/ grow over time: old cache files accumulate on the disk until manually deleted or removed by a custom script. On large sites, this leads to gigabytes of unnecessary data, slower backups, and hitting hosting quotas.
The solution is implemented as a single module. After installation, the agent automatically finds and deletes only unnecessary files at intervals of several hours. The active cache is preserved, so the site does not lose performance or rebuild pages from scratch as it would after a full reset.
Module capabilities:
Removes cache with expired lifetime. The expiration time is determined directly from the cache file content, not inferred from the modification date. This uses the same mechanism as the standard Bitrix cleanup.
Cleans up the deferred deletion queue: when Bitrix resets tagged cache, it renames directories to the .~N format and places them in a queue. The module completes this cleanup.
The module performs additional cache cleanup based on file age. Each directory has its own threshold in hours: cache, managed_cache, stack_cache, html_pages (including composite cache), upload/resize_cache, upload/tmp. The mode is disabled by default and must be enabled separately for each directory.
The script does not overload the server: a limited number of files are deleted within a set time per run, with the remainder processed in subsequent runs. Parallel execution is prevented by a locking mechanism.
Results are displayed in a desktop gadget showing the number of deleted files, freed space, and the time until the next run. A "Run Now" button allows immediate execution without page reload.
Every run is logged in the Bitrix event log.
Cleanup can be triggered via cron or manually by running the command php bitrix/modules/tenletters.oldcache/cli/clean.php.
Developers can use the OnBeforeOldCacheClean and OnAfterOldCacheClean events: the former allows cancellation of the run, while the latter provides execution statistics.
Security
The module never deletes all files indiscriminately; only files officially recognized as obsolete are removed.
The module deletes only files and empty directories within the specified cache cleaning folders. Symbolic links inside them are not processed. Cache files are removed by expiration time only if they physically reside in the cache, managed_cache, or stack_cache directories.
Settings and manual execution are available exclusively to administrators. AJAX requests are protected by a CSRF token.
The module does not create database tables or modify core files. When the module is removed, the agent, settings, and gadget copy are automatically uninstalled.
Quick Setup
After installation, the module automatically registers the agent with a 6-hour interval. Expiration-based cleaning is enabled immediately. If needed, you can open the settings to activate age-based cleaning for specific directories and adjust the interval and limits.
Frequently Asked Questions
Will the module delete necessary cache? No. Expiration-based cleaning removes only files whose validity period has expired. Age-based cleaning (disabled by default) may also remove active cache older than the set threshold. Bitrix will rebuild it upon the next request, so the first page loads may be slightly slower.
How often should it run? By default, once every 6 hours. The minimum interval is 300 seconds; more frequent execution is usually unnecessary.
If the cache has accumulated to an excessive volume, increase the file limit per run or execute the manual cleanup several times in succession. The actual constraint on execution duration is the time limit; the file limit counter tracks only successfully deleted files.
To disable automatic cleanup without removing the module, clear the 'Module enabled' checkbox. The agent and CLI script will then stop running, but all settings will be preserved and the option for manual execution will remain available.
Information about the module's actions can be found in the gadget and in the event log. To view this, navigate to 'Settings → Event log' and apply a filter for the tenletters.oldcache module. A link to the log is available directly on the settings page.
General iT can connect “Clearing outdated cache”, install and configure the module, and make sure the integration works correctly.