/** * Get host by url * @param string $url * @param boolean $force get from database * @return array */ public static function get_url_by_url($url, $force = false) { $host = self::get_or_create_host_by_url($url); if (!$host || !isset($host['id']) || $host['id'] == 0) { return false; } $host_id = intval($host['id']); $cache_id = $host_id . '-' . implode('-', db::create_url_params_from_url($url)); if (!CacheManager::getInstance('urls')->get($cache_id) || $force) { CacheManager::getInstance('urls')->set($cache_id, db::get_url_by_url($host_id, $url)); } return CacheManager::getInstance('urls')->get($cache_id); }
/** * Handle expired cache or update times_used counter */ private function validateCache() { $manager = CacheManager::getInstance(); $today = date(self::TIMESTAMP_FORMAT); $entry = $manager->getSingleItem(array('uid'), array('uid' => $this->uid, 'expires' => array('operator' => '<', 'value' => $today))); if (is_object($entry)) { // object needs to be expired unlink($this->cache_file); $manager->deleteData(array('uid' => $this->uid)); } else { // update times used $manager->updateData(array('times_used' => '`times_used` + 1'), array('uid' => $this->uid)); } }