NegativeDnsCache.php 846 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Http\Client;
  8. use OCP\ICache;
  9. use OCP\ICacheFactory;
  10. class NegativeDnsCache {
  11. /** @var ICache */
  12. private $cache;
  13. public function __construct(ICacheFactory $memcache) {
  14. $this->cache = $memcache->createLocal('NegativeDnsCache');
  15. }
  16. private function createCacheKey(string $domain, int $type) : string {
  17. return $domain . '-' . (string)$type;
  18. }
  19. public function setNegativeCacheForDnsType(string $domain, int $type, int $ttl) : void {
  20. $this->cache->set($this->createCacheKey($domain, $type), 'true', $ttl);
  21. }
  22. public function isNegativeCached(string $domain, int $type) : bool {
  23. return (bool)$this->cache->hasKey($this->createCacheKey($domain, $type));
  24. }
  25. }