Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 504799

CONTRIBUTION: Autoptimize Cache Size Under Control By Schedule Auto-cache Purge

$
0
0

Replies: 1

Autoptimize does not have its proper cache purging mechanism, and it does display a notice on the administration pages if the cache size surpasses the half a Gigabyte mark. But it does not automatically purge the cache.

Here is an updated quick solution which can keep the cache size under control without adding any extra cron jobs.

As an example, I have limited the cache upto 256MB, and you need to add this code inside functions.php file of your activated theme.


# Automatically clear autoptimizeCache if it goes beyond 256MB
if (class_exists('autoptimizeCache')) {
    $myMaxSize = 256000; # You may change this value to lower like 100000 for 100MB if you have limited server space
    $statArr=autoptimizeCache::stats();
    $cacheSize=round($statArr[1]/1024);

    if ($cacheSize>$myMaxSize){
       autoptimizeCache::clearall();
       header("Refresh:0"); # Refresh the page so that autoptimize can create new cache files and it does breaks the page after clearall.
    }
}

Note: Even if you deactivate the plugin, this code will not create any fatal error as it does check if plugin is activated by checking its class_exists


Viewing all articles
Browse latest Browse all 504799

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>