Update source into github
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Whois;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class CachedWhoisRepository implements WhoisRepositoryInterface
|
||||
{
|
||||
protected string $cachePrefix = 'whois';
|
||||
protected int $cacheTtl = 3600; // 1 hour
|
||||
|
||||
/**
|
||||
* Get domain information from cache
|
||||
*
|
||||
* @param string $domain
|
||||
* @return array|null
|
||||
*/
|
||||
public function getDomainInfo(string $domain): ?array
|
||||
{
|
||||
$cacheKey = $this->getCacheKey($domain);
|
||||
return Cache::get($cacheKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache domain information
|
||||
*
|
||||
* @param string $domain
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function cacheDomainInfo(string $domain, array $data): bool
|
||||
{
|
||||
$cacheKey = $this->getCacheKey($domain);
|
||||
return Cache::put($cacheKey, $data, $this->cacheTtl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear domain cache
|
||||
*
|
||||
* @param string $domain
|
||||
* @return bool
|
||||
*/
|
||||
public function clearDomainCache(string $domain): bool
|
||||
{
|
||||
$cacheKey = $this->getCacheKey($domain);
|
||||
return Cache::forget($cacheKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all whois cache
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clearAllCache(): bool
|
||||
{
|
||||
return Cache::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate cache key for domain
|
||||
*
|
||||
* @param string $domain
|
||||
* @return string
|
||||
*/
|
||||
protected function getCacheKey(string $domain): string
|
||||
{
|
||||
return "{$this->cachePrefix}.domain." . strtolower($domain);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Whois;
|
||||
|
||||
interface WhoisRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Get domain information from cache
|
||||
*
|
||||
* @param string $domain
|
||||
* @return array|null
|
||||
*/
|
||||
public function getDomainInfo(string $domain): ?array;
|
||||
|
||||
/**
|
||||
* Cache domain information
|
||||
*
|
||||
* @param string $domain
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function cacheDomainInfo(string $domain, array $data): bool;
|
||||
|
||||
/**
|
||||
* Clear domain cache
|
||||
*
|
||||
* @param string $domain
|
||||
* @return bool
|
||||
*/
|
||||
public function clearDomainCache(string $domain): bool;
|
||||
|
||||
/**
|
||||
* Clear all whois cache
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clearAllCache(): bool;
|
||||
}
|
||||
Reference in New Issue
Block a user