Skip to content

Instantly share code, notes, and snippets.

@lukecav
Last active November 18, 2021 16:52
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lukecav/8e690a19b151002a4ab42dae767efb76 to your computer and use it in GitHub Desktop.
Save lukecav/8e690a19b151002a4ab42dae767efb76 to your computer and use it in GitHub Desktop.
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.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment