/** * Constructor * @param string $slug */ public function __construct($slug) { $Database = AppCore::GetDatabase(); $Cache = AppCore::GetMemcached(); $mckey = "railpage:news.article_slug=" . $slug; $loaded = false; if ($story_id = $Cache->fetch($mckey)) { try { parent::__construct($story_id); $loaded = true; } catch (Exception $e) { } } /** * Fall back to a database query if we can't load the news article from Memcached */ if (!$loaded) { $story_id = $Database->fetchOne("SELECT sid FROM nuke_stories WHERE slug = ?", $slug); if (filter_var($story_id, FILTER_VALIDATE_INT)) { $Cache->save($mckey, $story_id, strtotime("+6 months")); parent::__construct($story_id); } else { throw new Exception("Could not find a story matching URL slug " . $slug); return false; } } }
/** * Constructor * @param string $slug */ public function __construct($slug) { global $ZendDB, $ZendDB_ReadOnly; $mckey = "railpage:news.article_slug=" . $slug; if ($story_id = getMemcacheObject($mckey)) { parent::__construct($story_id); } else { $story_id = $ZendDB_ReadOnly->fetchOne("SELECT sid FROM nuke_stories WHERE slug = ?", $slug); if (filter_var($story_id, FILTER_VALIDATE_INT)) { setMemcacheObject($mckey, $story_id, strtotime("+6 months")); parent::__construct($story_id); } else { throw new \Exception("Could not find a story matching URL slug " . $slug); return false; } } }