Autoptimize for WordPress: Automatic Cache Cleaning

All of you who use WordPress together with Autoptimize Plugin they will know it : The does not automatically delete Cached files, and must be done manually.

Autoptimize

Especially if you have the "Aggregate inline JS" and "Aggregate inline CSS" functions enabled, the amount of data collected in the cache files storage folder is huge.

So the forced to manually delete the specific files.

Below we will see some lines που αν προστεθούν στο functions.php του τος που χρησιμοποιείτε θα κάνουν όλη τη 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=($statArr[1]/1024);
    
    if ($cacheSize>$iguruMaxSize){
       autoptimizeCache::clearall();
       header("Refresh:0");
    }
}

Φυσικά μπορείτε να αλλάξετε την τιμή στο $iguruMaxSize στο 1024MB αν δεν θελετε να επιβαρύνετε το σας με συνεχιζόμενα 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.

iGuRu.gr The Best Technology Site in Greecefgns

Subscribe to Blog by Email

Subscribe to this blog and receive notifications of new posts by email.

Written by giorgos

George still wonders what he's doing here ...

Leave a reply

Your email address is not published. Required fields are mentioned with *

Your message will not be published if:
1. Contains insulting, defamatory, racist, offensive or inappropriate comments.
2. Causes harm to minors.
3. It interferes with the privacy and individual and social rights of other users.
4. Advertises products or services or websites.
5. Contains personal information (address, phone, etc.).