/** * Updates the cache and adds the given URL (+shortened) to the cache. It * also handles cleaning the cache of old entries as well. * * @param string $url The URL to add to the cache * @param string $shortenedUrl The shortened to add to the cache * * @return bool */ protected function updateUrlCache($url, $shortenedUrl) { $cache = array(); $source = $this->getEvent()->getSource(); /** * Transform URL (+shortened) into HEX CRC32 checksum to prevent * problems and minimize cache size for less bloat */ $url = $this->getUrlChecksum($url); $shortenedUrl = $this->getUrlChecksum($shortenedUrl); $time = time(); /** * Handle URL cache and remove old entries that surpass the limit if * enabled */ $cache['urlCache'][$source][$url] = $time; if ($this->limit > 0 && count($cache['urlCache'][$source]) > $this->limit) { asort($cache['urlCache'][$source], SORT_NUMERIC); array_shift($cache['urlCache'][$source]); } /** * Handle shortened cache and remove old entries that surpass the * limit if enabled */ $cache['shortCache'][$source][$shortenedUrl] = $time; if ($this->limit > 0 && count($cache['shortCache'][$source]) > $this->limit) { asort($cache['shortCache'][$source], SORT_NUMERIC); array_shift($cache['shortCache'][$source]); } $this->cache->store('urlCache', $cache['urlCache'], $this->expire); $this->cache->store('shortCache', $cache['shortCache'], $this->expire); unset($url, $shortenedUrl, $time); }