public function lookup($url)
{
// Look for url to url alias id cache
// Replace slashes by "|" to be sure not to mix cache key combinations in underlying lib.
$cacheKey = $url ?: '/';
$cache = $this->cache->getItem('urlAlias', 'url', $cacheKey);
$urlAliasId = $cache->get();
if ($cache->isMiss()) {
$urlAliasHistoryCache = $this->cache->getItem('urlAlias', 'url', 'history', $cacheKey);
$historyUrlAlias = $urlAliasHistoryCache->get();
if (!$urlAliasHistoryCache->isMiss()) {
return $historyUrlAlias;
}
// Also cache "not found" as this function is heavliy used and hance should be cached
try {
$this->logger->logCall(__METHOD__, array('url' => $url));
$urlAlias = $this->persistenceHandler->urlAliasHandler()->lookup($url);
if ($urlAlias->isHistory) {
$urlAliasHistoryCache->set($urlAlias)->save();
} else {
$cache->set($urlAlias->id)->save();
$urlAliasCache = $this->cache->getItem('urlAlias', $urlAlias->id);
$urlAliasCache->set($urlAlias)->save();
}
} catch (APINotFoundException $e) {
$cache->set(self::NOT_FOUND)->save();
throw $e;
}
} elseif ($urlAliasId === self::NOT_FOUND) {
throw new NotFoundException('UrlAlias', $url);
} else {
$urlAlias = $this->loadUrlAlias($urlAliasId);
}
return $urlAlias;
}