/** * Destructor */ function __destruct() { if (self::$destroyed == true) { return; } // Avoid cleaning the cache multiple times if (1 == rand(1, 5)) { $this->cleanCache(); } // 1 in 5 chance self::$destroyed = true; }