67 lines
1.5 KiB
PHP
67 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Whois;
|
|
|
|
use App\Services\Cache\CacheServiceInterface;
|
|
use App\Support\Cache\CacheKey;
|
|
|
|
class CachedWhoisRepository implements WhoisRepositoryInterface
|
|
{
|
|
protected CacheServiceInterface $cache;
|
|
|
|
public function __construct(CacheServiceInterface $cache)
|
|
{
|
|
$this->cache = $cache;
|
|
}
|
|
|
|
/**
|
|
* Get domain information from cache
|
|
*
|
|
* @param string $domain
|
|
* @return array|null
|
|
*/
|
|
public function getDomainInfo(string $domain): ?array
|
|
{
|
|
$cacheKey = CacheKey::build('whois', 'domain', ['domain' => strtolower($domain)]);
|
|
return $this->cache->get($cacheKey);
|
|
}
|
|
|
|
/**
|
|
* Cache domain information
|
|
*
|
|
* @param string $domain
|
|
* @param array $data
|
|
* @return bool
|
|
*/
|
|
public function cacheDomainInfo(string $domain, array $data): bool
|
|
{
|
|
$cacheKey = CacheKey::build('whois', 'domain', ['domain' => strtolower($domain)]);
|
|
$this->cache->put($cacheKey, $data);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Clear domain cache
|
|
*
|
|
* @param string $domain
|
|
* @return bool
|
|
*/
|
|
public function clearDomainCache(string $domain): bool
|
|
{
|
|
$cacheKey = CacheKey::build('whois', 'domain', ['domain' => strtolower($domain)]);
|
|
$this->cache->forget($cacheKey);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Clear all whois cache
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function clearAllCache(): bool
|
|
{
|
|
$this->cache->clearByModule('whois');
|
|
return true;
|
|
}
|
|
}
|