Files
shopPRO/autoload/Domain/Cache/CacheRepository.php
Jacek Pyziak 1c88f8adfa Add new settings and cache repository files, update admin settings controller and templates
- Introduced new `SettingsRepository` and `CacheRepository` classes in the `autoload\Domain` namespace.
- Updated `SettingsController` in the `admin\Controllers` namespace to enhance settings management.
- Added new templates for settings in `admin\templates\settings` and `admin\templates\site`.
- Improved overall structure and organization of settings-related files.
2026-02-05 23:32:48 +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 \RedisConnection $redisConnection Połączenie z Redis (nullable)
* @param string $basePath Ścieżka bazowa do katalogów cache
*/
public function __construct(
?\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
];
}
}