refactor: implement centralized cache key management and add utility traits for vCenter SSH operations.

This commit is contained in:
pbao9
2026-05-16 16:52:21 +07:00
parent 06dbd54ecd
commit 8a115c5175
36 changed files with 1694 additions and 517 deletions
@@ -2,13 +2,18 @@
namespace App\Repositories\Whois;
use Illuminate\Support\Facades\Cache;
use App\Services\Cache\CacheServiceInterface;
use App\Support\Cache\CacheKey;
class CachedWhoisRepository implements WhoisRepositoryInterface
{
protected string $cachePrefix = 'whois';
protected int $cacheTtl = 3600; // 1 hour
protected CacheServiceInterface $cache;
public function __construct(CacheServiceInterface $cache)
{
$this->cache = $cache;
}
/**
* Get domain information from cache
*
@@ -17,10 +22,10 @@ class CachedWhoisRepository implements WhoisRepositoryInterface
*/
public function getDomainInfo(string $domain): ?array
{
$cacheKey = $this->getCacheKey($domain);
return Cache::get($cacheKey);
$cacheKey = CacheKey::build('whois', 'domain', ['domain' => strtolower($domain)]);
return $this->cache->get($cacheKey);
}
/**
* Cache domain information
*
@@ -30,10 +35,11 @@ class CachedWhoisRepository implements WhoisRepositoryInterface
*/
public function cacheDomainInfo(string $domain, array $data): bool
{
$cacheKey = $this->getCacheKey($domain);
return Cache::put($cacheKey, $data, $this->cacheTtl);
$cacheKey = CacheKey::build('whois', 'domain', ['domain' => strtolower($domain)]);
$this->cache->put($cacheKey, $data);
return true;
}
/**
* Clear domain cache
*
@@ -42,10 +48,11 @@ class CachedWhoisRepository implements WhoisRepositoryInterface
*/
public function clearDomainCache(string $domain): bool
{
$cacheKey = $this->getCacheKey($domain);
return Cache::forget($cacheKey);
$cacheKey = CacheKey::build('whois', 'domain', ['domain' => strtolower($domain)]);
$this->cache->forget($cacheKey);
return true;
}
/**
* Clear all whois cache
*
@@ -53,17 +60,7 @@ class CachedWhoisRepository implements WhoisRepositoryInterface
*/
public function clearAllCache(): bool
{
return Cache::flush();
$this->cache->clearByModule('whois');
return true;
}
/**
* Generate cache key for domain
*
* @param string $domain
* @return string
*/
protected function getCacheKey(string $domain): string
{
return "{$this->cachePrefix}.domain." . strtolower($domain);
}
}
}