/** * Checks if the entry is expired and redirects to a non-expired entry. * * @param UrlCacheEntry $cacheEntry */ protected function checkExpiration(UrlCacheEntry $cacheEntry) { if ($cacheEntry->getExpiration() > 0) { $newerCacheEntry = $this->cache->getUrlFromCacheByOriginalUrl($cacheEntry->getRootPageId(), $cacheEntry->getOriginalUrl()); if ($newerCacheEntry->getExpiration() === 0) { if ($cacheEntry->getSpeakingUrl() !== $newerCacheEntry->getSpeakingUrl()) { @ob_end_clean(); header(self::REDIRECT_STATUS_HEADER); header(self::REDIRECT_INFO_HEADER . ': redirecting expired URL to a fresh one'); header('Location: ' . GeneralUtility::locationHeaderUrl($newerCacheEntry->getSpeakingUrl())); die; } else { // Got expired and non-expired entry for the same speaking url. Remove expired one. $this->cache->clearUrlCacheById($cacheEntry->getCacheId()); } } } }
/** * Sets the entry to cache. * * @param UrlCacheEntry $cacheEntry * @return void */ public function putUrlToCache(UrlCacheEntry $cacheEntry) { $data = array('expire' => $cacheEntry->getExpiration(), 'original_url' => $cacheEntry->getOriginalUrl(), 'page_id' => $cacheEntry->getPageId(), 'request_variables' => json_encode($cacheEntry->getRequestVariables()), 'rootpage_id' => $cacheEntry->getRootPageId(), 'speaking_url' => $cacheEntry->getSpeakingUrl()); if ($cacheEntry->getCacheId()) { $this->databaseConnection->exec_UPDATEquery('tx_realurl_urldata', 'uid=' . $this->databaseConnection->fullQuoteStr($cacheEntry->getCacheId(), 'tx_realurl_urldata'), $data); } else { $this->databaseConnection->sql_query('START TRANSACTION'); if ($this->limitTableRecords('tx_realurl_urldata')) { $this->databaseConnection->sql_query('DELETE FROM tx_realurl_uniqalias_cache_map WHERE url_cache_id NOT IN (SELECT uid FROM tx_realurl_urldata)'); } $this->databaseConnection->exec_INSERTquery('tx_realurl_urldata', $data); $cacheEntry->setCacheId($this->databaseConnection->sql_insert_id()); $this->databaseConnection->sql_query('COMMIT'); } }