private function _possiblyClearCache() { $cleaningFactor = $this->_context->get(tubepress_api_options_Names::CACHE_CLEANING_FACTOR); $cleaningFactor = intval($cleaningFactor); /* * Handle cleaning factor. */ if ($cleaningFactor > 0 && rand(1, $cleaningFactor) === 1) { $this->_apiCache->flush(); } }
/** * Performs all actions that are needed to update database structure. * * @return boolean True if the system updated successfully and false * otherwise. */ public function run() { $current_version = $this->getDatabaseVersion(); if (!preg_match("/^([0-9]{1,2}\\.){2}[0-9]{1,2}(-(alpha|beta|rc)\\.[0-9]+)?\$/", $current_version)) { $this->errors[] = getlocal('The current version ({0}) is unknown or wrong formated', array($current_version)); return false; } if (version_compare($current_version, MIBEW_VERSION) == 0) { $this->log[] = getlocal('The database is already up to date'); return true; } if (version_compare($current_version, self::MIN_VERSION) < 0) { $this->errors[] = getlocal('You can update the system only from {0} and later versions. The current version is {1}', array(self::MIN_VERSION, $current_version)); return false; } try { // Perform incremental updates foreach (Utils::getUpdates($this) as $version => $method) { if (version_compare($version, $current_version) <= 0) { // Skip updates to lower versions. continue; } // Run the update if (!$method()) { $this->errors[] = getlocal('Cannot update to {0}', array($version)); return false; } // Store new version number in the database. With this info // we can rerun the updating process if one of pending // updates fails. if (!$this->setDatabaseVersion($version)) { return false; } else { $this->log[] = getlocal('Updated to {0}', array($version)); } $current_version = $version; } } catch (\Exception $e) { // Something went wrong $this->errors[] = getlocal('Update failed: {0}', array($e->getMessage())); return false; } // Use the version from the PHP's constant as the current database // version. if ($this->setDatabaseVersion(MIBEW_VERSION)) { return false; } // Clean up the cache $this->cache->flush(); return true; }
/** * clear all keys and data from the cache. * * @return boolean True if the cache was successfully cleared, false otherwise */ public function clear() { return $this->pool->flush(); }