feat: implement repository architecture with smart caching

- Add base repository interfaces and abstract classes
  - Implement separated read/write repositories for Domain and Username models
  - Add intelligent query caching with automatic invalidation
  - Include cache management service and CLI commands
  - Add comprehensive configuration for cache TTL and monitoring
  - Enhance performance through optimized data access patterns
This commit is contained in:
idevakk
2025-11-15 22:11:19 -08:00
parent ea0bc91251
commit 4615d384be
15 changed files with 1928 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
<?php
namespace App\Console\Commands;
use App\Services\CacheService;
use Illuminate\Console\Command;
class WarmUpRepositoryCache extends Command
{
protected $signature = 'repo:cache:warm
{--force : Force warm-up without confirmation}';
protected $description = 'Warm up repository cache with frequently accessed data';
public function __construct(
protected CacheService $cacheService
) {
parent::__construct();
}
public function handle(): int
{
if (! config('repositories.cache.warming.enabled', false)) {
$this->error('Cache warming is disabled in configuration.');
return Command::FAILURE;
}
if (! $this->option('force') && ! $this->confirm('Warm up repository cache?')) {
$this->info('Cache warm-up cancelled.');
return Command::SUCCESS;
}
$this->info('Warming up repository cache...');
$this->cacheService->warmUpCache();
$this->info('Repository cache warmed up successfully.');
$stats = $this->cacheService->getCacheStats();
$this->table(['Metric', 'Value'], [
['Memory Usage', $this->formatBytes($stats['memory_usage'])],
['Peak Memory', $this->formatBytes($stats['peak_memory'])],
['Cache Tags', implode(', ', $stats['tags'])],
]);
return Command::SUCCESS;
}
protected function formatBytes(int $bytes): string
{
$units = ['B', 'KB', 'MB', 'GB'];
$unitIndex = 0;
while ($bytes >= 1024 && $unitIndex < count($units) - 1) {
$bytes /= 1024;
$unitIndex++;
}
return round($bytes, 2).' '.$units[$unitIndex];
}
}