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>
This commit is contained in:
2026-02-16 21:25:50 +01:00
parent 53d945843a
commit 8e97413361
54 changed files with 594 additions and 346 deletions

View File

@@ -0,0 +1,60 @@
<?php
namespace Shared\Cache;
class CacheHandler
{
protected $redis;
public function __construct()
{
if (class_exists('Redis')) {
try {
$this->redis = RedisConnection::getInstance()->getConnection();
} catch (\Exception $e) {
$this->redis = null;
}
}
}
public function get($key)
{
if ($this->redis) {
return $this->redis->get($key);
}
return null;
}
public function set($key, $value, $ttl = 86400)
{
if ($this->redis) {
$this->redis->setex($key, $ttl, serialize($value));
}
}
public function exists($key)
{
if ($this->redis) {
return $this->redis->exists($key);
}
return false;
}
public function delete($key)
{
if ($this->redis) {
return $this->redis->del($key);
}
return false;
}
public function deletePattern($pattern)
{
if ($this->redis) {
$keys = $this->redis->keys($pattern);
if (!empty($keys)) {
return $this->redis->del($keys);
}
}
return false;
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Shared\Cache;
class RedisConnection
{
private static $instance = null;
private $redis;
private function __construct()
{
global $config;
$this->redis = new \Redis();
try {
if (!$this->redis->connect($config['redis']['host'], $config['redis']['port'])) {
error_log("Nie udalo sie polaczyc z serwerem Redis.");
$this->redis = null;
return;
}
if (!$this->redis->auth($config['redis']['password'])) {
error_log("Autoryzacja do serwera Redis nie powiodla sie.");
$this->redis = null;
return;
}
} catch (\Exception $e) {
error_log("Blad podczas polaczenia z Redis: " . $e->getMessage());
$this->redis = null;
}
}
public static function getInstance()
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
public function getConnection()
{
return $this->redis;
}
}