public function __destruct()
{
// @todo Check size and age, clean up accordingly
$size = 0;
$dir = $this->getVariable("cache_path");
// Short circuit if both size and age are unlimited
if ($this->getVariable("max_age") == 0 && $this->getVariable("max_size") == 0) {
return;
}
$exclude = array(".", "..");
$files = scandir($dir);
if (!$files) {
throw new \IOException($dir . " is not a directory.");
}
// Perform cleanup
foreach ($files as $f) {
if (!in_array($f, $exclude)) {
$stat = stat($dir . $f);
// Add size
$size .= $stat['size'];
// Is this older than my maximum date?
if ($this->getVariable("max_age") > 0 && time() - $stat['mtime'] > $this->getVariable("max_age")) {
unlink($dir . $f);
}
// @todo Size
}
}
}