Files
shopPRO/autoload/Domain/Cache/CacheRepository.php
Jacek Pyziak 8e97413361 ver. 0.282: Banners frontend migration, Cache cleanup, Shared\Cache namespace
- Banners frontend: front\Views\Banners (new), BannerRepository +2 frontend methods,
  front\view\Site przepięty, usunięte front\factory\Banners i front\view\Banners
- Cache cleanup: eliminacja legacy class.Cache.php (file-based cache),
  13 metod front\factory przepiętych z \Cache::fetch/store na CacheHandler
- Shared\Cache namespace: CacheHandler i RedisConnection przeniesione do Shared\Cache\,
  60 odwołań CacheHandler i 12 odwołań RedisConnection przepiętych,
  usunięte backward-compat wrappery class.CacheHandler.php i class.RedisConnection.php
- Naprawione rozbieżności kluczy cache (random_products, category_name)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 21:25:50 +01:00

54 lines
1.5 KiB
PHP

<?php
namespace Domain\Cache;
/**
* Repozytorium zarządzania cache (katalogi + Redis)
*
* Wyodrębniona logika czyszczenia cache z wstrzykiwanymi zależnościami.
* Obecnie nie używane przez SettingsController (cache czyszczony bezpośrednio).
* Przygotowane na przyszłe użycie w innych kontrolerach.
*/
class CacheRepository
{
private $redisConnection;
private $basePath;
/**
* @param \Shared\Cache\RedisConnection $redisConnection Połączenie z Redis (nullable)
* @param string $basePath Ścieżka bazowa do katalogów cache
*/
public function __construct(
?\Shared\Cache\RedisConnection $redisConnection = null,
string $basePath = '../'
) {
$this->redisConnection = $redisConnection;
$this->basePath = $basePath;
}
/**
* Czyszczenie całego cache (katalogi + Redis)
*
* @return array ['success' => bool, 'message' => string]
*/
public function clearCache(): array
{
\S::delete_dir( $this->basePath . 'temp/' );
\S::delete_dir( $this->basePath . 'thumbs/' );
$redisCleared = false;
if ( $this->redisConnection ) {
$redis = $this->redisConnection->getConnection();
if ( $redis ) {
$redis->flushAll();
$redisCleared = true;
}
}
return [
'success' => true,
'message' => 'Cache został wyczyszczony.',
'redisCleared' => $redisCleared
];
}
}