Skip to content

Instantly share code, notes, and snippets.

View maowebsolutions's full-sized avatar

Marcelo Oliveira maowebsolutions

View GitHub Profile
@lukecav
lukecav / functions.php
Last active November 18, 2021 16:52
Autoptimize Automatic Cache Purge - Set to be 2GB in size
// Automatically clear Autoptimize cache if it goes beyond 2GB
if (class_exists('autoptimizeCache')) {
$myMaxSize = 2000000; # You may change this value to lower like 500000 for 500MB 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.
}