Rework admin panel and other
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user