cacheTtl = TimeToLive::convert($cacheTtl); } public function fetch(string $uri): ?TopLevelDomainList { $cacheKey = $this->cacheKey($uri); $topLevelDomainList = $this->cache->get($cacheKey); if (null === $topLevelDomainList) { return null; } if (!$topLevelDomainList instanceof TopLevelDomainList) { $this->cache->delete($cacheKey); return null; } return $topLevelDomainList; } /** * Returns the cache key according to the source URL. */ private function cacheKey(string $str): string { return $this->cachePrefix.md5(strtolower($str)); } public function remember(string $uri, TopLevelDomainList $topLevelDomainList): bool { try { return $this->cache->set($this->cacheKey($uri), $topLevelDomainList, $this->cacheTtl); } catch (Throwable $exception) { if ($exception instanceof CacheException) { return false; } throw $exception; } } public function forget(string $uri): bool { return $this->cache->delete($this->cacheKey($uri)); } }