Rework admin panel and other

This commit is contained in:
F4ilji
2025-04-02 18:37:20 +05:00
parent 49072e50c7
commit 5cd6ff11b5
198 changed files with 9715 additions and 6664 deletions
+18 -38
View File
@@ -2,62 +2,42 @@
namespace App\Services\App\Cache;
use App\Enums\CacheKeys;
use App\Models\Page;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;
class PageCacheService extends AbstractCacheService implements CacheInterface
{
/**
* Очищает кеш, связанный с постом.
*
* @param mixed $entity Пост или связанная сущность
* @return void
*/
private const DEFAULT_TTL = 3600;
public function clearCache($entity): void
{
$cacheKeyByPath = md5($entity->path);
$cacheKeyById = md5($entity->id);
Cache::forget('page_' . $cacheKeyByPath);
Cache::forget('page_' . $cacheKeyById);
Cache::forget('navigation');
if ($entity instanceof Page) {
$this->clearAllCacheByModel();
$this->clearNavigationCache();
}
}
public function clearAllCacheByModel(): void
{
$this->clearCacheByPrefix('page_*');
$this->clearCacheByPrefix('page_data_*');
Cache::forget('navigation');
$this->clearCacheByPrefix(CacheKeys::PAGE_PREFIX->value.'*');
$this->clearCacheByPrefix(CacheKeys::PAGE_DATA_PREFIX->value.'*');
$this->clearNavigationCache();
}
/**
* Получает кешированные данные по ключу.
*
* @param string $key Ключ кеша
* @return mixed
*/
public function getCachedData(string $key)
{
return Cache::get($key);
}
/**
* Кеширует данные по ключу.
*
* @param string $key Ключ кеша
* @param mixed $data Данные для кеширования
* @param int $ttl Время жизни кеша в секундах
* @return void
*/
public function cacheData(string $key, $data, int $ttl = 3600): void
public function cacheData(string $key, $data, int $ttl = null): void
{
Cache::put($key, $data, $ttl);
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
}
private function clearNavigationCache(): void
{
Cache::forget(CacheKeys::NAVIGATION_PREFIX->value);
}
}