- 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>
61 lines
1.2 KiB
PHP
61 lines
1.2 KiB
PHP
<?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;
|
|
}
|
|
}
|