All of you who use WordPress together with Autoptimize Plugin will know the problem: The add-on does not automatically delete Cached files, and must be done manually.
Especially if you have them enabled functions "Aggregate inline JS" and "Aggregate inline CSS" the amount of data collected in the storage folder of the cache files is huge.
So the manager is forced to manually delete those files.
Below we will see a few lines of code that if added to its functions.php themethat you use will do all the work for you.
We quote the code we use in SecNews, through WPress.gr. It is configured to delete the cached files when the 512MB volume reaches.
//* Clear autoptimize cache at 512MB iGuRu.gr if (class_exists('autoptimizeCache')) { $iguruMaxSize = 512000; $statArr=autoptimizeCache::stats(); $cacheSize=round($statArr[1]/1024); if ($cacheSize>$iguruMaxSize){ autoptimizeCache::clearall(); header("Refresh:0"); } }
Of course you can change it price in $iguruMaxSize to 1024MB if you don't want to burden your sites with continuous php queries.
If you want to change the size, convert 1024MB to KB aka: 1024000.
That's it! The next time you will not need to manually delete the cahced files. At the end of the code as you see there is also a refresh in the header.